EcsEc2ContainerDefinition
A container orchestrated by ECS that uses EC2 resources.
Example
declare const myFileSystem: efs.IFileSystem;
declare const myJobRole: iam.Role;
myFileSystem.grantRead(myJobRole);
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
volumes: [batch.EcsVolume.efs({
name: 'myVolume',
fileSystem: myFileSystem,
containerPath: '/Volumes/myVolume',
useJobRole: true,
})],
jobRole: myJobRole,
}),
});
# my_file_system: efs.IFileSystem
# my_job_role: iam.Role
my_file_system.grant_read(my_job_role)
job_defn = batch.EcsJobDefinition(self, "JobDefn",
container=batch.EcsEc2ContainerDefinition(self, "containerDefn",
image=ecs.ContainerImage.from_registry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
memory=cdk.Size.mebibytes(2048),
cpu=256,
volumes=[batch.EcsVolume.efs(
name="myVolume",
file_system=my_file_system,
container_path="/Volumes/myVolume",
use_job_role=True
)],
job_role=my_job_role
)
)
IFileSystem myFileSystem;
Role myJobRole;
myFileSystem.grantRead(myJobRole);
EcsJobDefinition jobDefn = EcsJobDefinition.Builder.create(this, "JobDefn")
.container(EcsEc2ContainerDefinition.Builder.create(this, "containerDefn")
.image(ContainerImage.fromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"))
.memory(Size.mebibytes(2048))
.cpu(256)
.volumes(List.of(EcsVolume.efs(EfsVolumeOptions.builder()
.name("myVolume")
.fileSystem(myFileSystem)
.containerPath("/Volumes/myVolume")
.useJobRole(true)
.build())))
.jobRole(myJobRole)
.build())
.build();
// Install: dotnet add package Amazon.CDK.Lib
IFileSystem myFileSystem;
Role myJobRole;
myFileSystem.GrantRead(myJobRole);
var jobDefn = new EcsJobDefinition(this, "JobDefn", new EcsJobDefinitionProps {
Container = new EcsEc2ContainerDefinition(this, "containerDefn", new EcsEc2ContainerDefinitionProps {
Image = ContainerImage.FromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
Memory = Size.Mebibytes(2048),
Cpu = 256,
Volumes = new [] { EcsVolume.Efs(new EfsVolumeOptions {
Name = "myVolume",
FileSystem = myFileSystem,
ContainerPath = "/Volumes/myVolume",
UseJobRole = true
}) },
JobRole = myJobRole
})
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var myFileSystem IFileSystem
var myJobRole Role
myFileSystem.GrantRead(myJobRole)
jobDefn := batch.NewEcsJobDefinition(this, jsii.String("JobDefn"), &EcsJobDefinitionProps{
Container: batch.NewEcsEc2ContainerDefinition(this, jsii.String("containerDefn"), &EcsEc2ContainerDefinitionProps{
Image: ecs.ContainerImage_FromRegistry(jsii.String("public.ecr.aws/amazonlinux/amazonlinux:latest")),
Memory: cdk.Size_Mebibytes(jsii.Number(2048)),
Cpu: jsii.Number(256),
Volumes: []EcsVolume{
batch.EcsVolume_Efs(&EfsVolumeOptions{
Name: jsii.String("myVolume"),
FileSystem: myFileSystem,
ContainerPath: jsii.String("/Volumes/myVolume"),
UseJobRole: jsii.Boolean(true),
}),
},
JobRole: myJobRole,
}),
})
Initializer
new EcsEc2ContainerDefinition(scope: Construct, id: string, props: EcsEc2ContainerDefinitionProps)
EcsEc2ContainerDefinition(scope: Construct, id: str, props: EcsEc2ContainerDefinitionProps)
new EcsEc2ContainerDefinition(Construct scope, String id, EcsEc2ContainerDefinitionProps props)
new EcsEc2ContainerDefinition(Construct scope, string id, EcsEc2ContainerDefinitionProps props)
NewEcsEc2ContainerDefinition(Scope Construct, Id *string, Props EcsEc2ContainerDefinitionProps)
Construct Props
commandoptionalstring[]commandoptionaltyping.List[str]commandoptionalList<String>Commandoptionalstring[]Commandoptional*[]*string#Default: no command
Each vCPU is equivalent to 1,024 CPU shares. For containers running on EC2 resources, you must specify at least one vCPU.
enableExecuteCommandoptionalbooleanenable_execute_commandoptionalboolenableExecuteCommandoptionalBooleanEnableExecuteCommandoptionalboolEnableExecuteCommandoptional*bool#Default: undefined - AWS Batch default is false
notes
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.
environmentoptional{ [key: string]: string }environmentoptionaltyping.Mapping[str, str]environmentoptionalMap<String, String>EnvironmentoptionalIDictionary<string, string>Environmentoptional*map[string]*string#Default: no environment variables
Cannot start with AWS_BATCH. We don't recommend using plaintext environment variables for sensitive information, such as credential data.
executionRoleoptionalIRoleexecution_roleoptionalIRoleexecutionRoleoptionalIRoleExecutionRoleoptionalIRoleExecutionRoleoptionalIRole#Default: a Role will be created
Default: no gpus
Make sure that the number of GPUs reserved for all containers in a job doesn't exceed the number of available GPUs on the compute resource that the job is launched on.
imageContainerImageimageContainerImageimageContainerImageImageContainerImageImageContainerImagerequired#jobRoleoptionalIRolejob_roleoptionalIRolejobRoleoptionalIRoleJobRoleoptionalIRoleJobRoleoptionalIRole#Default: no job role
linuxParametersoptionalLinuxParameterslinux_parametersoptionalLinuxParameterslinuxParametersoptionalLinuxParametersLinuxParametersoptionalLinuxParametersLinuxParametersoptionalLinuxParameters= none#loggingoptionalLogDriverloggingoptionalLogDriverloggingoptionalLogDriverLoggingoptionalLogDriverLoggingoptionalLogDriver#Default: the log configuration of the Docker daemon
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.
privilegedoptionalbooleanprivilegedoptionalboolprivilegedoptionalBooleanPrivilegedoptionalboolPrivilegedoptional*bool= false#readonlyRootFilesystemoptionalbooleanreadonly_root_filesystemoptionalboolreadonlyRootFilesystemoptionalBooleanReadonlyRootFilesystemoptionalboolReadonlyRootFilesystemoptional*bool= false#secretsoptional{ [key: string]: Secret }secretsoptionaltyping.Mapping[str, Secret]secretsoptionalMap<String, Secret>SecretsoptionalIDictionary<string, Secret>Secretsoptional*map[string]Secret#Default: no secrets
Allows your job definitions to reference the secret by the environment variable name defined in this property.
ulimitsoptionalUlimit[]ulimitsoptionaltyping.List[Ulimit]ulimitsoptionalList<Ulimit>UlimitsoptionalUlimit[]Ulimitsoptional*[]Ulimit#Default: no ulimits
Default: no user
Properties
commandmay be undefinedstring[]commandmay be undefinedtyping.List[str]commandmay be undefinedList<String>Commandmay be undefinedstring[]Commandmay be undefined*[]*string#Each vCPU is equivalent to 1,024 CPU shares. For containers running on EC2 resources, you must specify at least one vCPU.
enableExecuteCommandmay be undefinedbooleanenable_execute_commandmay be undefinedboolenableExecuteCommandmay be undefinedBooleanEnableExecuteCommandmay be undefinedboolEnableExecuteCommandmay be undefined*bool#environmentmay be undefined{ [key: string]: string }environmentmay be undefinedtyping.Mapping[str, str]environmentmay be undefinedMap<String, String>Environmentmay be undefinedIDictionary<string, string>Environmentmay be undefined*map[string]*string#Cannot start with AWS_BATCH. We don't recommend using plaintext environment variables for sensitive information, such as credential data.
gpumay be undefinednumbergpumay be undefinedint | floatgpumay be undefinedNumberGpumay be undefineddoubleGpumay be undefined*float64#Make sure that the number of GPUs reserved for all containers in a job doesn't exceed the number of available GPUs on the compute resource that the job is launched on.
jobRolemay be undefinedIRolejob_rolemay be undefinedIRolejobRolemay be undefinedIRoleJobRolemay be undefinedIRoleJobRolemay be undefinedIRole#linuxParametersmay be undefinedLinuxParameterslinux_parametersmay be undefinedLinuxParameterslinuxParametersmay be undefinedLinuxParametersLinuxParametersmay be undefinedLinuxParametersLinuxParametersmay be undefinedLinuxParameters#logDriverConfigmay be undefinedLogDriverConfiglog_driver_configmay be undefinedLogDriverConfiglogDriverConfigmay be undefinedLogDriverConfigLogDriverConfigmay be undefinedLogDriverConfigLogDriverConfigmay be undefinedLogDriverConfig#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.
privilegedmay be undefinedbooleanprivilegedmay be undefinedboolprivilegedmay be undefinedBooleanPrivilegedmay be undefinedboolPrivilegedmay be undefined*bool#PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#readonlyRootFilesystemmay be undefinedbooleanreadonly_root_filesystemmay be undefinedboolreadonlyRootFilesystemmay be undefinedBooleanReadonlyRootFilesystemmay be undefinedboolReadonlyRootFilesystemmay be undefined*bool#secretsmay be undefined{ [key: string]: Secret }secretsmay be undefinedtyping.Mapping[str, Secret]secretsmay be undefinedMap<String, Secret>Secretsmay be undefinedIDictionary<string, Secret>Secretsmay be undefined*map[string]Secret#Allows your job definitions to reference the secret by the environment variable name defined in this property.
usermay be undefinedstringusermay be undefinedstrusermay be undefinedStringUsermay be undefinedstringUsermay be undefined*string#Methods
addUlimit(ulimit: Ulimit): voiddef add_ulimit(self, ulimit: Ulimit) -> Nonepublic void addUlimit(Ulimit ulimit)public void AddUlimit(Ulimit ulimit)func AddUlimit(Ulimit Ulimit)#addVolume(volume: EcsVolume): voiddef add_volume(self, volume: EcsVolume) -> Nonepublic void addVolume(EcsVolume volume)public void AddVolume(EcsVolume volume)func AddVolume(Volume EcsVolume)#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#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#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#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