Show / Hide Table of Contents

Class ContainerDefinition

A container definition is used in a task definition to describe the containers that are launched as part of a task.

Inheritance
object
ContainerDefinition
FirelensLogRouter
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,
                MinHealthyPercent = 100,
                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(Construct, string, IContainerDefinitionProps)

Constructs a new instance of the ContainerDefinition class.

Properties

CONTAINER_PORT_USE_RANGE

A container definition is used in a task definition to describe the containers that are launched as part of a task.

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.

PROPERTY_INJECTION_ID

Uniquely identifies this class.

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(params 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(params 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(params IMountPoint[])

This method adds one or more mount points for data volumes to the container.

AddPortMappings(params 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(params IUlimit[])

This method adds one or more ulimits to the container.

AddVolumesFrom(params 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(Construct, string, IContainerDefinitionProps)

Constructs a new instance of the ContainerDefinition class.

public ContainerDefinition(Construct scope, string id, IContainerDefinitionProps props)
Parameters
scope Construct
id string
props IContainerDefinitionProps
Remarks

ExampleMetadata: infused

Properties

CONTAINER_PORT_USE_RANGE

A container definition is used in a task definition to describe the containers that are launched as part of a task.

public static double CONTAINER_PORT_USE_RANGE { get; }
Property Value

double

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,
                MinHealthyPercent = 100,
                CloudMapOptions = new CloudMapOptions {
                    // Create SRV records - useful for bridge networking
                    DnsRecordType = DnsRecordType.SRV,
                    // Targets port TCP port 7600 `specificContainer`
                    Container = specificContainer,
                    ContainerPort = 7600
                }
            });

ContainerDependencies

An array dependencies defined for container startup and shutdown.

public virtual IContainerDependency[] ContainerDependencies { get; }
Property Value

IContainerDependency[]

Remarks

ExampleMetadata: infused

ContainerName

The name of this container.

public virtual string ContainerName { get; }
Property Value

string

Remarks

ExampleMetadata: infused

ContainerPort

The port the container will listen on.

public virtual double ContainerPort { get; }
Property Value

double

Remarks

ExampleMetadata: infused

Cpu

The number of cpu units reserved for the container.

public virtual double? Cpu { get; }
Property Value

double?

Remarks

ExampleMetadata: infused

CredentialSpecs

The crdential specifications for this container.

public virtual ICredentialSpecConfig[]? CredentialSpecs { get; }
Property Value

ICredentialSpecConfig[]

Remarks

ExampleMetadata: infused

EnvironmentFiles

The environment files for this container.

public virtual IEnvironmentFileConfig[]? EnvironmentFiles { get; }
Property Value

IEnvironmentFileConfig[]

Remarks

ExampleMetadata: infused

Essential

Specifies whether the container will be marked essential.

public virtual bool Essential { get; }
Property Value

bool

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

string

Remarks

ExampleMetadata: infused

IngressPort

The inbound rules associated with the security group the task or service will use.

public virtual double IngressPort { get; }
Property Value

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

LinuxParameters

Remarks

ExampleMetadata: infused

LogDriverConfig

The log configuration specification for the container.

public virtual ILogDriverConfig? LogDriverConfig { get; }
Property Value

ILogDriverConfig

Remarks

ExampleMetadata: infused

MemoryLimitSpecified

Whether there was at least one memory limit specified in this definition.

public virtual bool MemoryLimitSpecified { get; }
Property Value

bool

Remarks

ExampleMetadata: infused

MountPoints

The mount points for data volumes in your container.

public virtual IMountPoint[] MountPoints { get; }
Property Value

IMountPoint[]

Remarks

ExampleMetadata: infused

PROPERTY_INJECTION_ID

Uniquely identifies this class.

public static string PROPERTY_INJECTION_ID { get; }
Property Value

string

Remarks

ExampleMetadata: infused

PortMappings

The list of port mappings for the container.

public virtual IPortMapping[] PortMappings { get; }
Property Value

IPortMapping[]

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 bool? PseudoTerminal { get; }
Property Value

bool?

Remarks

ExampleMetadata: infused

ReferencesSecretJsonField

Whether this container definition references a specific JSON field of a secret stored in Secrets Manager.

public virtual bool? ReferencesSecretJsonField { get; }
Property Value

bool?

Remarks

ExampleMetadata: infused

TaskDefinition

The name of the task definition that includes this container definition.

public virtual TaskDefinition TaskDefinition { get; }
Property Value

TaskDefinition

Remarks

ExampleMetadata: infused

Ulimits

An array of ulimits to set in the container.

public virtual IUlimit[] Ulimits { get; }
Property Value

IUlimit[]

Remarks

ExampleMetadata: infused

VolumesFrom

The data volumes to mount from another container in the same task definition.

public virtual IVolumeFrom[] VolumesFrom { get; }
Property Value

IVolumeFrom[]

Remarks

ExampleMetadata: infused

Methods

AddContainerDependencies(params IContainerDependency[])

This method adds one or more container dependencies to the container.

public virtual void AddContainerDependencies(params IContainerDependency[] containerDependencies)
Parameters
containerDependencies IContainerDependency[]
Remarks

ExampleMetadata: infused

AddDockerLabel(string, string)

This method adds a Docker label to the container.

public virtual void AddDockerLabel(string name, string value)
Parameters
name string
value string
Remarks

ExampleMetadata: infused

AddEnvironment(string, string)

This method adds an environment variable to the container.

public virtual void AddEnvironment(string name, string value)
Parameters
name string
value string
Remarks

ExampleMetadata: infused

AddInferenceAcceleratorResource(params string[])

This method adds one or more resources to the container.

public virtual void AddInferenceAcceleratorResource(params string[] inferenceAcceleratorResources)
Parameters
inferenceAcceleratorResources string[]
Remarks

ExampleMetadata: infused

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 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(params 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[]
Remarks

ExampleMetadata: infused

AddPortMappings(params IPortMapping[])

This method adds one or more port mappings to the container.

public virtual void AddPortMappings(params IPortMapping[] portMappings)
Parameters
portMappings IPortMapping[]
Remarks

ExampleMetadata: infused

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 string
secret Secret
Remarks

ExampleMetadata: infused

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
Remarks

ExampleMetadata: infused

AddUlimits(params IUlimit[])

This method adds one or more ulimits to the container.

public virtual void AddUlimits(params IUlimit[] ulimits)
Parameters
ulimits IUlimit[]
Remarks

ExampleMetadata: infused

AddVolumesFrom(params IVolumeFrom[])

This method adds one or more volumes to the container.

public virtual void AddVolumesFrom(params IVolumeFrom[] volumesFrom)
Parameters
volumesFrom IVolumeFrom[]
Remarks

ExampleMetadata: infused

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 double
protocol Protocol
Returns

IPortMapping

Remarks

ExampleMetadata: infused

FindPortMappingByName(string)

Returns the port mapping with the given name, if it exists.

public virtual IPortMapping? FindPortMappingByName(string name)
Parameters
name string
Returns

IPortMapping

Remarks

ExampleMetadata: infused

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

Remarks

ExampleMetadata: infused

Back to top Generated by DocFX