Class ContainerDefinition
- All Implemented Interfaces:
IConstruct
,IDependable
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
- Direct Known Subclasses:
FirelensLogRouter
Example:
TaskDefinition taskDefinition; Cluster cluster; // Add a container to the task definition ContainerDefinition specificContainer = taskDefinition.addContainer("Container", ContainerDefinitionOptions.builder() .image(ContainerImage.fromRegistry("/aws/aws-example-app")) .memoryLimitMiB(2048) .build()); // Add a port mapping specificContainer.addPortMappings(PortMapping.builder() .containerPort(7600) .protocol(Protocol.TCP) .build()); Ec2Service.Builder.create(this, "Service") .cluster(cluster) .taskDefinition(taskDefinition) .cloudMapOptions(CloudMapOptions.builder() // Create SRV records - useful for bridge networking .dnsRecordType(DnsRecordType.SRV) // Targets port TCP port 7600 `specificContainer` .container(specificContainer) .containerPort(7600) .build()) .build();
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.amazon.awscdk.core.IConstruct
IConstruct.Jsii$Default, IConstruct.Jsii$Proxy
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default, software.constructs.IConstruct.Jsii$Proxy
-
Constructor Summary
ModifierConstructorDescriptionprotected
ContainerDefinition
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
ContainerDefinition
(software.amazon.jsii.JsiiObjectRef objRef) ContainerDefinition
(software.constructs.Construct scope, String id, ContainerDefinitionProps props) Constructs a new instance of the ContainerDefinition class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addContainerDependencies
(@NotNull ContainerDependency... containerDependencies) This method adds one or more container dependencies to the container.void
addEnvironment
(String name, String value) This method adds an environment variable to the container.void
addInferenceAcceleratorResource
(@NotNull String... inferenceAcceleratorResources) This method adds one or more resources to the container.void
addLink
(ContainerDefinition container) This method adds a link which allows containers to communicate with each other without the need for port mappings.void
addLink
(ContainerDefinition container, String alias) This method adds a link which allows containers to communicate with each other without the need for port mappings.void
addMountPoints
(@NotNull MountPoint... mountPoints) This method adds one or more mount points for data volumes to the container.void
addPortMappings
(@NotNull PortMapping... portMappings) This method adds one or more port mappings to the container.void
addScratch
(ScratchSpace scratch) This method mounts temporary disk space to the container.void
addToExecutionPolicy
(PolicyStatement statement) This method adds the specified statement to the IAM task execution policy in the task definition.void
addUlimits
(@NotNull Ulimit... ulimits) This method adds one or more ulimits to the container.void
addVolumesFrom
(@NotNull VolumeFrom... volumesFrom) This method adds one or more volumes to the container.findPortMapping
(Number containerPort, Protocol protocol) Returns the host port for the requested container port if it exists.An array dependencies defined for container startup and shutdown.The name of this container.The port the container will listen on.The environment files for this container.Specifies whether the container will be marked essential.The name of the image referenced by this container.The inbound rules associated with the security group the task or service will use.The Linux-specific modifications that are applied to the container, such as Linux kernel capabilities.The log configuration specification for the container.Whether there was at least one memory limit specified in this definition.The mount points for data volumes in your container.The list of port mappings for the container.Whether this container definition references a specific JSON field of a secret stored in Secrets Manager.The name of the task definition that includes this container definition.An array of ulimits to set in the container.The data volumes to mount from another container in the same task definition.Render this container definition to a CloudFormation object.renderContainerDefinition
(TaskDefinition _taskDefinition) Render this container definition to a CloudFormation object.Methods inherited from class software.amazon.awscdk.core.Construct
getNode, isConstruct, onPrepare, onSynthesize, onValidate, prepare, synthesize, validate
Methods inherited from class software.constructs.Construct
toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
ContainerDefinition
protected ContainerDefinition(software.amazon.jsii.JsiiObjectRef objRef) -
ContainerDefinition
protected ContainerDefinition(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
ContainerDefinition
@Stability(Stable) public ContainerDefinition(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull ContainerDefinitionProps props) Constructs a new instance of the ContainerDefinition class.- Parameters:
scope
- This parameter is required.id
- This parameter is required.props
- This parameter is required.
-
-
Method Details
-
addContainerDependencies
@Stability(Stable) public void addContainerDependencies(@NotNull @NotNull ContainerDependency... containerDependencies) This method adds one or more container dependencies to the container.- Parameters:
containerDependencies
- This parameter is required.
-
addEnvironment
This method adds an environment variable to the container.- Parameters:
name
- This parameter is required.value
- This parameter is required.
-
addInferenceAcceleratorResource
@Stability(Stable) public void addInferenceAcceleratorResource(@NotNull @NotNull String... inferenceAcceleratorResources) This method adds one or more resources to the container.- Parameters:
inferenceAcceleratorResources
- This parameter is required.
-
addLink
@Stability(Stable) public void addLink(@NotNull ContainerDefinition container, @Nullable String alias) This method adds a link which allows containers to communicate with each other without the need for port mappings.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.
- Parameters:
container
- This parameter is required.alias
-
-
addLink
This method adds a link which allows containers to communicate with each other without the need for port mappings.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.
- Parameters:
container
- This parameter is required.
-
addMountPoints
This method adds one or more mount points for data volumes to the container.- Parameters:
mountPoints
- This parameter is required.
-
addPortMappings
This method adds one or more port mappings to the container.- Parameters:
portMappings
- This parameter is required.
-
addScratch
This method mounts temporary disk space to the container.This adds the correct container mountPoint and task definition volume.
- Parameters:
scratch
- This parameter is required.
-
addToExecutionPolicy
This method adds the specified statement to the IAM task execution policy in the task definition.- Parameters:
statement
- This parameter is required.
-
addUlimits
This method adds one or more ulimits to the container.- Parameters:
ulimits
- This parameter is required.
-
addVolumesFrom
This method adds one or more volumes to the container.- Parameters:
volumesFrom
- This parameter is required.
-
findPortMapping
@Stability(Stable) @Nullable public PortMapping findPortMapping(@NotNull Number containerPort, @NotNull Protocol protocol) Returns the host port for the requested container port if it exists.- Parameters:
containerPort
- This parameter is required.protocol
- This parameter is required.
-
renderContainerDefinition
@Stability(Stable) @NotNull public CfnTaskDefinition.ContainerDefinitionProperty renderContainerDefinition(@Nullable TaskDefinition _taskDefinition) Render this container definition to a CloudFormation object.- Parameters:
_taskDefinition
- [disable-awslint:ref-via-interface] (unused but kept to avoid breaking change).
-
renderContainerDefinition
@Stability(Stable) @NotNull public CfnTaskDefinition.ContainerDefinitionProperty renderContainerDefinition()Render this container definition to a CloudFormation object. -
getContainerDependencies
An array dependencies defined for container startup and shutdown. -
getContainerName
The name of this container. -
getContainerPort
The port the container will listen on. -
getEssential
Specifies whether the container will be marked essential.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.
-
getImageName
The name of the image referenced by this container. -
getIngressPort
The inbound rules associated with the security group the task or service will use.This property is only used for tasks that use the awsvpc network mode.
-
getMemoryLimitSpecified
Whether there was at least one memory limit specified in this definition. -
getMountPoints
The mount points for data volumes in your container. -
getPortMappings
The list of port mappings for the container.Port mappings allow containers to access ports on the host container instance to send or receive traffic.
-
getTaskDefinition
The name of the task definition that includes this container definition. -
getUlimits
An array of ulimits to set in the container. -
getVolumesFrom
The data volumes to mount from another container in the same task definition. -
getEnvironmentFiles
The environment files for this container. -
getLinuxParameters
The Linux-specific modifications that are applied to the container, such as Linux kernel capabilities. -
getLogDriverConfig
The log configuration specification for the container. -
getReferencesSecretJsonField
Whether this container definition references a specific JSON field of a secret stored in Secrets Manager.
-