Class ContainerDefinition
A container definition is used in a task definition to describe the containers that are launched as part of a task.
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class ContainerDefinition : Construct
Syntax (vb)
Public Class ContainerDefinition
Inherits Construct
Remarks
ExampleMetadata: infused
Examples
TaskDefinition taskDefinition;
Cluster cluster;
// Add a container to the task definition
var specificContainer = taskDefinition.AddContainer("Container", new ContainerDefinitionOptions {
Image = ContainerImage.FromRegistry("/aws/aws-example-app"),
MemoryLimitMiB = 2048
});
// Add a port mapping
specificContainer.AddPortMappings(new PortMapping {
ContainerPort = 7600,
Protocol = Protocol.TCP
});
new Ec2Service(this, "Service", new Ec2ServiceProps {
Cluster = cluster,
TaskDefinition = taskDefinition,
CloudMapOptions = new CloudMapOptions {
// Create SRV records - useful for bridge networking
DnsRecordType = DnsRecordType.SRV,
// Targets port TCP port 7600 `specificContainer`
Container = specificContainer,
ContainerPort = 7600
}
});
Synopsis
Constructors
ContainerDefinition(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
ContainerDefinition(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
ContainerDefinition(Construct, String, IContainerDefinitionProps) | Constructs a new instance of the ContainerDefinition class. |
Properties
CONTAINER_PORT_USE_RANGE | |
ContainerDependencies | An array dependencies defined for container startup and shutdown. |
ContainerName | The name of this container. |
ContainerPort | The port the container will listen on. |
Cpu | The number of cpu units reserved for the container. |
CredentialSpecs | The crdential specifications for this container. |
EnvironmentFiles | The environment files for this container. |
Essential | Specifies whether the container will be marked essential. |
ImageName | The name of the image referenced by this container. |
IngressPort | The inbound rules associated with the security group the task or service will use. |
LinuxParameters | The Linux-specific modifications that are applied to the container, such as Linux kernel capabilities. |
LogDriverConfig | The log configuration specification for the container. |
MemoryLimitSpecified | Whether there was at least one memory limit specified in this definition. |
MountPoints | The mount points for data volumes in your container. |
PortMappings | The list of port mappings for the container. |
PseudoTerminal | Specifies whether a TTY must be allocated for this container. |
ReferencesSecretJsonField | Whether this container definition references a specific JSON field of a secret stored in Secrets Manager. |
TaskDefinition | The name of the task definition that includes this container definition. |
Ulimits | An array of ulimits to set in the container. |
VolumesFrom | The data volumes to mount from another container in the same task definition. |
Methods
AddContainerDependencies(IContainerDependency[]) | This method adds one or more container dependencies to the container. |
AddDockerLabel(String, String) | This method adds a Docker label to the container. |
AddEnvironment(String, String) | This method adds an environment variable to the container. |
AddInferenceAcceleratorResource(String[]) | This method adds one or more resources to the container. |
AddLink(ContainerDefinition, String) | This method adds a link which allows containers to communicate with each other without the need for port mappings. |
AddMountPoints(IMountPoint[]) | This method adds one or more mount points for data volumes to the container. |
AddPortMappings(IPortMapping[]) | This method adds one or more port mappings to the container. |
AddScratch(IScratchSpace) | This method mounts temporary disk space to the container. |
AddSecret(String, Secret) | This method adds a secret as environment variable to the container. |
AddToExecutionPolicy(PolicyStatement) | This method adds the specified statement to the IAM task execution policy in the task definition. |
AddUlimits(IUlimit[]) | This method adds one or more ulimits to the container. |
AddVolumesFrom(IVolumeFrom[]) | This method adds one or more volumes to the container. |
FindPortMapping(Double, Protocol) | Returns the host port for the requested container port if it exists. |
FindPortMappingByName(String) | Returns the port mapping with the given name, if it exists. |
RenderContainerDefinition(TaskDefinition) | Render this container definition to a CloudFormation object. |
Constructors
ContainerDefinition(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected ContainerDefinition(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
ContainerDefinition(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected ContainerDefinition(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
ContainerDefinition(Construct, String, IContainerDefinitionProps)
Constructs a new instance of the ContainerDefinition class.
public ContainerDefinition(Construct scope, string id, IContainerDefinitionProps props)
Parameters
- scope Constructs.Construct
- id System.String
- props IContainerDefinitionProps
Properties
CONTAINER_PORT_USE_RANGE
public static double CONTAINER_PORT_USE_RANGE { get; }
Property Value
System.Double
ContainerDependencies
An array dependencies defined for container startup and shutdown.
public virtual IContainerDependency[] ContainerDependencies { get; }
Property Value
ContainerName
The name of this container.
public virtual string ContainerName { get; }
Property Value
System.String
ContainerPort
The port the container will listen on.
public virtual double ContainerPort { get; }
Property Value
System.Double
Cpu
The number of cpu units reserved for the container.
public virtual Nullable<double> Cpu { get; }
Property Value
System.Nullable<System.Double>
CredentialSpecs
The crdential specifications for this container.
public virtual ICredentialSpecConfig[] CredentialSpecs { get; }
Property Value
EnvironmentFiles
The environment files for this container.
public virtual IEnvironmentFileConfig[] EnvironmentFiles { get; }
Property Value
Essential
Specifies whether the container will be marked essential.
public virtual bool Essential { get; }
Property Value
System.Boolean
Remarks
If the essential parameter of a container is marked as true, and that container fails or stops for any reason, all other containers that are part of the task are stopped. If the essential parameter of a container is marked as false, then its failure does not affect the rest of the containers in a task.
If this parameter is omitted, a container is assumed to be essential.
ImageName
The name of the image referenced by this container.
public virtual string ImageName { get; }
Property Value
System.String
IngressPort
The inbound rules associated with the security group the task or service will use.
public virtual double IngressPort { get; }
Property Value
System.Double
Remarks
This property is only used for tasks that use the awsvpc network mode.
LinuxParameters
The Linux-specific modifications that are applied to the container, such as Linux kernel capabilities.
public virtual LinuxParameters LinuxParameters { get; }
Property Value
LogDriverConfig
The log configuration specification for the container.
public virtual ILogDriverConfig LogDriverConfig { get; }
Property Value
MemoryLimitSpecified
Whether there was at least one memory limit specified in this definition.
public virtual bool MemoryLimitSpecified { get; }
Property Value
System.Boolean
MountPoints
The mount points for data volumes in your container.
public virtual IMountPoint[] MountPoints { get; }
Property Value
PortMappings
The list of port mappings for the container.
public virtual IPortMapping[] PortMappings { get; }
Property Value
Remarks
Port mappings allow containers to access ports on the host container instance to send or receive traffic.
PseudoTerminal
Specifies whether a TTY must be allocated for this container.
public virtual Nullable<bool> PseudoTerminal { get; }
Property Value
System.Nullable<System.Boolean>
ReferencesSecretJsonField
Whether this container definition references a specific JSON field of a secret stored in Secrets Manager.
public virtual Nullable<bool> ReferencesSecretJsonField { get; }
Property Value
System.Nullable<System.Boolean>
TaskDefinition
The name of the task definition that includes this container definition.
public virtual TaskDefinition TaskDefinition { get; }
Property Value
Ulimits
An array of ulimits to set in the container.
public virtual IUlimit[] Ulimits { get; }
Property Value
IUlimit[]
VolumesFrom
The data volumes to mount from another container in the same task definition.
public virtual IVolumeFrom[] VolumesFrom { get; }
Property Value
Methods
AddContainerDependencies(IContainerDependency[])
This method adds one or more container dependencies to the container.
public virtual void AddContainerDependencies(params IContainerDependency[] containerDependencies)
Parameters
- containerDependencies IContainerDependency[]
AddDockerLabel(String, String)
This method adds a Docker label to the container.
public virtual void AddDockerLabel(string name, string value)
Parameters
- name System.String
- value System.String
AddEnvironment(String, String)
This method adds an environment variable to the container.
public virtual void AddEnvironment(string name, string value)
Parameters
- name System.String
- value System.String
AddInferenceAcceleratorResource(String[])
This method adds one or more resources to the container.
public virtual void AddInferenceAcceleratorResource(params string[] inferenceAcceleratorResources)
Parameters
- inferenceAcceleratorResources System.String[]
AddLink(ContainerDefinition, String)
This method adds a link which allows containers to communicate with each other without the need for port mappings.
public virtual void AddLink(ContainerDefinition container, string alias = null)
Parameters
- container ContainerDefinition
- alias System.String
Remarks
This parameter is only supported if the task definition is using the bridge network mode. Warning: The --link flag is a legacy feature of Docker. It may eventually be removed.
AddMountPoints(IMountPoint[])
This method adds one or more mount points for data volumes to the container.
public virtual void AddMountPoints(params IMountPoint[] mountPoints)
Parameters
- mountPoints IMountPoint[]
AddPortMappings(IPortMapping[])
This method adds one or more port mappings to the container.
public virtual void AddPortMappings(params IPortMapping[] portMappings)
Parameters
- portMappings IPortMapping[]
AddScratch(IScratchSpace)
This method mounts temporary disk space to the container.
public virtual void AddScratch(IScratchSpace scratch)
Parameters
- scratch IScratchSpace
Remarks
This adds the correct container mountPoint and task definition volume.
AddSecret(String, Secret)
This method adds a secret as environment variable to the container.
public virtual void AddSecret(string name, Secret secret)
Parameters
- name System.String
- secret Secret
AddToExecutionPolicy(PolicyStatement)
This method adds the specified statement to the IAM task execution policy in the task definition.
public virtual void AddToExecutionPolicy(PolicyStatement statement)
Parameters
- statement PolicyStatement
AddUlimits(IUlimit[])
This method adds one or more ulimits to the container.
public virtual void AddUlimits(params IUlimit[] ulimits)
Parameters
- ulimits IUlimit[]
AddVolumesFrom(IVolumeFrom[])
This method adds one or more volumes to the container.
public virtual void AddVolumesFrom(params IVolumeFrom[] volumesFrom)
Parameters
- volumesFrom IVolumeFrom[]
FindPortMapping(Double, Protocol)
Returns the host port for the requested container port if it exists.
public virtual IPortMapping FindPortMapping(double containerPort, Protocol protocol)
Parameters
- containerPort System.Double
- protocol Protocol
Returns
FindPortMappingByName(String)
Returns the port mapping with the given name, if it exists.
public virtual IPortMapping FindPortMappingByName(string name)
Parameters
- name System.String
Returns
RenderContainerDefinition(TaskDefinition)
Render this container definition to a CloudFormation object.
public virtual CfnTaskDefinition.IContainerDefinitionProperty RenderContainerDefinition(TaskDefinition taskDefinition = null)
Parameters
- taskDefinition TaskDefinition
[disable-awslint:ref-via-interface] (unused but kept to avoid breaking change).
Returns
CfnTaskDefinition.IContainerDefinitionProperty