Skip to content
v2.273.0

EcsFargateContainerDefinition ​

A container orchestrated by ECS that uses Fargate resources.

Example ​

ts
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
  container: new batch.EcsFargateContainerDefinition(this, 'myFargateContainer', {
    image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
    memory: cdk.Size.mebibytes(2048),
    cpu: 256,
    ephemeralStorageSize: cdk.Size.gibibytes(100),
    fargateCpuArchitecture: ecs.CpuArchitecture.ARM64,
    fargateOperatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
  }),
});
python
job_defn = batch.EcsJobDefinition(self, "JobDefn",
    container=batch.EcsFargateContainerDefinition(self, "myFargateContainer",
        image=ecs.ContainerImage.from_registry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
        memory=cdk.Size.mebibytes(2048),
        cpu=256,
        ephemeral_storage_size=cdk.Size.gibibytes(100),
        fargate_cpu_architecture=ecs.CpuArchitecture.ARM64,
        fargate_operating_system_family=ecs.OperatingSystemFamily.LINUX
    )
)
java
EcsJobDefinition jobDefn = EcsJobDefinition.Builder.create(this, "JobDefn")
        .container(EcsFargateContainerDefinition.Builder.create(this, "myFargateContainer")
                .image(ContainerImage.fromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"))
                .memory(Size.mebibytes(2048))
                .cpu(256)
                .ephemeralStorageSize(Size.gibibytes(100))
                .fargateCpuArchitecture(CpuArchitecture.ARM64)
                .fargateOperatingSystemFamily(OperatingSystemFamily.LINUX)
                .build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var jobDefn = new EcsJobDefinition(this, "JobDefn", new EcsJobDefinitionProps {
    Container = new EcsFargateContainerDefinition(this, "myFargateContainer", new EcsFargateContainerDefinitionProps {
        Image = ContainerImage.FromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
        Memory = Size.Mebibytes(2048),
        Cpu = 256,
        EphemeralStorageSize = Size.Gibibytes(100),
        FargateCpuArchitecture = CpuArchitecture.ARM64,
        FargateOperatingSystemFamily = OperatingSystemFamily.LINUX
    })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
jobDefn := batch.NewEcsJobDefinition(this, jsii.String("JobDefn"), &EcsJobDefinitionProps{
	Container: batch.NewEcsFargateContainerDefinition(this, jsii.String("myFargateContainer"), &EcsFargateContainerDefinitionProps{
		Image: ecs.ContainerImage_FromRegistry(jsii.String("public.ecr.aws/amazonlinux/amazonlinux:latest")),
		Memory: cdk.Size_Mebibytes(jsii.Number(2048)),
		Cpu: jsii.Number(256),
		EphemeralStorageSize: cdk.Size_Gibibytes(jsii.Number(100)),
		FargateCpuArchitecture: ecs.CpuArchitecture_ARM64(),
		FargateOperatingSystemFamily: ecs.OperatingSystemFamily_LINUX(),
	}),
})

Initializer ​

ts
new EcsFargateContainerDefinition(scope: Construct, id: string, props: EcsFargateContainerDefinitionProps)
python
EcsFargateContainerDefinition(scope: Construct, id: str, props: EcsFargateContainerDefinitionProps)
java
new EcsFargateContainerDefinition(Construct scope, String id, EcsFargateContainerDefinitionProps props)
csharp
new EcsFargateContainerDefinition(Construct scope, string id, EcsFargateContainerDefinitionProps props)
go
NewEcsFargateContainerDefinition(Scope Construct, Id *string, Props EcsFargateContainerDefinitionProps)

Construct Props ​

assignPublicIpbooleanassign_public_ipboolassignPublicIpBooleanAssignPublicIpboolAssignPublicIp*bool= false#
Indicates whether the job has a public IP address.

For a job that's running on Fargate resources in a private subnet to send outbound traffic to the internet (for example, to pull container images), the private subnet requires a NAT gateway be attached to route requests to the internet.

commandstring[]commandtyping.List[str]commandList<String>Commandstring[]Command*[]*string= no command#
The command that's passed to the container.
cpunumbercpuint | floatcpuNumberCpudoubleCpu*float64required#
The number of vCPUs reserved for the container.

Each vCPU is equivalent to 1,024 CPU shares. For containers running on EC2 resources, you must specify at least one vCPU.

enableExecuteCommandbooleanenable_execute_commandboolenableExecuteCommandBooleanEnableExecuteCommandboolEnableExecuteCommand*bool= undefined - AWS Batch default is…#
Determines whether execute command functionality is turned on for this task.
notes · default

If true, execute command functionality is turned on all the containers in the task.

This allows you to use ECS Exec to access containers interactively. When enabled, a job role with required SSM permissions will be created automatically if no job role is provided. If a job role is alreadyprovided, the required permissions will be added to it.

Default: undefined - AWS Batch default is false

environment{ [key: string]: string }environmenttyping.Mapping[str, str]environmentMap<String, String>EnvironmentIDictionary<string, string>Environment*map[string]*string= no environment variables#
The environment variables to pass to a container.

Cannot start with AWS_BATCH. We don't recommend using plaintext environment variables for sensitive information, such as credential data.

ephemeralStorageSizeSizeephemeral_storage_sizeSizeephemeralStorageSizeSizeEphemeralStorageSizeSizeEphemeralStorageSizeSize= 20 GiB#
The size for ephemeral storage.
executionRoleIRoleexecution_roleIRoleexecutionRoleIRoleExecutionRoleIRoleExecutionRoleIRole= a Role will be created#
The role used by Amazon ECS container and AWS Fargate agents to make AWS API calls on your behalf.
fargateCpuArchitectureCpuArchitecturefargate_cpu_architectureCpuArchitecturefargateCpuArchitectureCpuArchitectureFargateCpuArchitectureCpuArchitectureFargateCpuArchitectureCpuArchitecture= X86_64#
The vCPU architecture of Fargate Runtime.
fargateOperatingSystemFamilyOperatingSystemFamilyfargate_operating_system_familyOperatingSystemFamilyfargateOperatingSystemFamilyOperatingSystemFamilyFargateOperatingSystemFamilyOperatingSystemFamilyFargateOperatingSystemFamilyOperatingSystemFamily= LINUX#
The operating system for the compute environment.
fargatePlatformVersionFargatePlatformVersionfargate_platform_versionFargatePlatformVersionfargatePlatformVersionFargatePlatformVersionFargatePlatformVersionFargatePlatformVersionFargatePlatformVersionFargatePlatformVersion= LATEST#
Which version of Fargate to use when running this container.
The image that this container will run.
jobRoleIRolejob_roleIRolejobRoleIRoleJobRoleIRoleJobRoleIRole= no job role#
The role that the container can assume.
linuxParametersLinuxParameterslinux_parametersLinuxParameterslinuxParametersLinuxParametersLinuxParametersLinuxParametersLinuxParametersLinuxParameters= none#
Linux-specific modifications that are applied to the container, such as details for device mappings.
loggingLogDriverloggingLogDriverloggingLogDriverLoggingLogDriverLoggingLogDriver= the log configuration of the Doc…#
The loging configuration for this Job.
default

Default: the log configuration of the Docker daemon

memorySizememorySizememorySizeMemorySizeMemorySizerequired#
The memory hard limit present to the container.

If your container attempts to exceed the memory specified, the container is terminated. You must specify at least 4 MiB of memory for a job.

readonlyRootFilesystembooleanreadonly_root_filesystemboolreadonlyRootFilesystemBooleanReadonlyRootFilesystemboolReadonlyRootFilesystem*bool= false#
Gives the container readonly access to its root filesystem.
secrets{ [key: string]: Secret }secretstyping.Mapping[str, Secret]secretsMap<String, Secret>SecretsIDictionary<string, Secret>Secrets*map[string]Secret= no secrets#
A map from environment variable names to the secrets for the container.

Allows your job definitions to reference the secret by the environment variable name defined in this property.

userstringuserstruserStringUserstringUser*string= no user#
The user name to use inside the container.
volumesEcsVolume[]volumestyping.List[EcsVolume]volumesList<EcsVolume>VolumesEcsVolume[]Volumes*[]EcsVolume= no volumes#
The volumes to mount to this container.

Automatically added to the job definition.

Properties ​

assignPublicIpbooleanassign_public_ipboolassignPublicIpBooleanAssignPublicIpboolAssignPublicIp*bool#
Indicates whether the job has a public IP address.

For a job that's running on Fargate resources in a private subnet to send outbound traffic to the internet (for example, to pull container images), the private subnet requires a NAT gateway be attached to route requests to the internet.

commandstring[]commandtyping.List[str]commandList<String>Commandstring[]Command*[]*string#
The command that's passed to the container.
cpunumbercpuint | floatcpuNumberCpudoubleCpu*float64required#
The number of vCPUs reserved for the container.

Each vCPU is equivalent to 1,024 CPU shares. For containers running on EC2 resources, you must specify at least one vCPU.

enableExecuteCommandbooleanenable_execute_commandboolenableExecuteCommandBooleanEnableExecuteCommandboolEnableExecuteCommand*bool#
Whether to enable ecs exec for this container.
environment{ [key: string]: string }environmenttyping.Mapping[str, str]environmentMap<String, String>EnvironmentIDictionary<string, string>Environment*map[string]*string#
The environment variables to pass to a container.

Cannot start with AWS_BATCH. We don't recommend using plaintext environment variables for sensitive information, such as credential data.

ephemeralStorageSizeSizeephemeral_storage_sizeSizeephemeralStorageSizeSizeEphemeralStorageSizeSizeEphemeralStorageSizeSize#
The size for ephemeral storage.
executionRoleIRoleexecution_roleIRoleexecutionRoleIRoleExecutionRoleIRoleExecutionRoleIRolerequired#
The role used by Amazon ECS container and AWS Fargate agents to make AWS API calls on your behalf.
fargateCpuArchitectureCpuArchitecturefargate_cpu_architectureCpuArchitecturefargateCpuArchitectureCpuArchitectureFargateCpuArchitectureCpuArchitectureFargateCpuArchitectureCpuArchitecture#
The vCPU architecture of Fargate Runtime.
fargateOperatingSystemFamilyOperatingSystemFamilyfargate_operating_system_familyOperatingSystemFamilyfargateOperatingSystemFamilyOperatingSystemFamilyFargateOperatingSystemFamilyOperatingSystemFamilyFargateOperatingSystemFamilyOperatingSystemFamily#
The operating system for the compute environment.
fargatePlatformVersionFargatePlatformVersionfargate_platform_versionFargatePlatformVersionfargatePlatformVersionFargatePlatformVersionFargatePlatformVersionFargatePlatformVersionFargatePlatformVersionFargatePlatformVersion#
Which version of Fargate to use when running this container.
The image that this container will run.
jobRoleIRolejob_roleIRolejobRoleIRoleJobRoleIRoleJobRoleIRole#
The role that the container can assume.
linuxParametersLinuxParameterslinux_parametersLinuxParameterslinuxParametersLinuxParametersLinuxParametersLinuxParametersLinuxParametersLinuxParameters#
Linux-specific modifications that are applied to the container, such as details for device mappings.
logDriverConfigLogDriverConfiglog_driver_configLogDriverConfiglogDriverConfigLogDriverConfigLogDriverConfigLogDriverConfigLogDriverConfigLogDriverConfig#
The configuration of the log driver.
memorySizememorySizememorySizeMemorySizeMemorySizerequired#
The memory hard limit present to the container.

If your container attempts to exceed the memory specified, the container is terminated. You must specify at least 4 MiB of memory for a job.

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
readonlyRootFilesystembooleanreadonly_root_filesystemboolreadonlyRootFilesystemBooleanReadonlyRootFilesystemboolReadonlyRootFilesystem*bool#
Gives the container readonly access to its root filesystem.
secrets{ [key: string]: Secret }secretstyping.Mapping[str, Secret]secretsMap<String, Secret>SecretsIDictionary<string, Secret>Secrets*map[string]Secret#
A map from environment variable names to the secrets for the container.

Allows your job definitions to reference the secret by the environment variable name defined in this property.

userstringuserstruserStringUserstringUser*string#
The user name to use inside the container.
volumesEcsVolume[]volumestyping.List[EcsVolume]volumesList<EcsVolume>VolumesEcsVolume[]Volumes*[]EcsVolumerequired#
The volumes to mount to this container.

Automatically added to the job definition.

Methods ​

addVolume(volume: EcsVolume): voiddef add_volume(self, volume: EcsVolume) -> Nonepublic void addVolume(EcsVolume volume)public void AddVolume(EcsVolume volume)func AddVolume(Volume EcsVolume)#
Add a Volume to this container.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining