Skip to content
v2.273.0

EcsJobDefinition L2 construct ​

A JobDefinition that uses ECS orchestration.

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 EcsJobDefinition(scope: Construct, id: string, props: EcsJobDefinitionProps)
python
EcsJobDefinition(scope: Construct, id: str, props: EcsJobDefinitionProps)
java
new EcsJobDefinition(Construct scope, String id, EcsJobDefinitionProps props)
csharp
new EcsJobDefinition(Construct scope, string id, EcsJobDefinitionProps props)
go
NewEcsJobDefinition(Scope Construct, Id *string, Props EcsJobDefinitionProps)

Construct Props ​

The container that this job will run.
jobDefinitionNamestringjob_definition_namestrjobDefinitionNameStringJobDefinitionNamestringJobDefinitionName*string= generated by CloudFormation#
The name of this job definition.
parameters{ [key: string]: any }parameterstyping.Mapping[str, Any]parametersMap<String, Object>ParametersIDictionary<string, object>Parameters*map[string]interface{}= none#
The default parameters passed to the container These parameters can be referenced in the `command` that you give to the container.
propagateTagsbooleanpropagate_tagsboolpropagateTagsBooleanPropagateTagsboolPropagateTags*bool= false#
Whether to propagate tags from the JobDefinition to the ECS task that Batch spawns.
retryAttemptsnumberretry_attemptsint | floatretryAttemptsNumberRetryAttemptsdoubleRetryAttempts*float64= 1#
The number of times to retry a job.

The job is retried on failure the same number of attempts as the value.

retryStrategiesRetryStrategy[]retry_strategiestyping.List[RetryStrategy]retryStrategiesList<RetryStrategy>RetryStrategiesRetryStrategy[]RetryStrategies*[]RetryStrategy= no `RetryStrategy`#
Defines the retry behavior for this job.
schedulingPrioritynumberscheduling_priorityint | floatschedulingPriorityNumberSchedulingPrioritydoubleSchedulingPriority*float64= none#
The priority of this Job.

Only used in Fairshare Scheduling to decide which job to run first when there are multiple jobs with the same share identifier.

skipDeregisterOnUpdatebooleanskip_deregister_on_updateboolskipDeregisterOnUpdateBooleanSkipDeregisterOnUpdateboolSkipDeregisterOnUpdate*bool= undefined - AWS Batch default is…#
Specifies whether the previous revision of the job definition is retained in an active status after UPDATE events for the resource.

When the property is set to false, the previous revision of the job definition is de-registered after a new revision is created. When the property is set to true, the previous revision of the job definition is not de-registered.

default

Default: undefined - AWS Batch default is false

timeoutDurationtimeoutDurationtimeoutDurationTimeoutDurationTimeoutDuration= no timeout#
The timeout time for jobs that are submitted with this job definition.

After the amount of time you specify passes, Batch terminates your jobs if they aren't finished.

Properties ​

The container that this job will run.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

jobDefinitionArnstringjob_definition_arnstrjobDefinitionArnStringJobDefinitionArnstringJobDefinitionArn*stringrequired#
The ARN of this job definition.
jobDefinitionNamestringjob_definition_namestrjobDefinitionNameStringJobDefinitionNamestringJobDefinitionName*stringrequired#
The name of this job definition.
jobDefinitionRefJobDefinitionReferencejob_definition_refJobDefinitionReferencejobDefinitionRefJobDefinitionReferenceJobDefinitionRefJobDefinitionReferenceJobDefinitionRefJobDefinitionReferencerequired#
A reference to a JobDefinition resource.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
parameters{ [key: string]: any }parameterstyping.Mapping[str, Any]parametersMap<String, Object>ParametersIDictionary<string, object>Parameters*map[string]interface{}#
The default parameters passed to the container These parameters can be referenced in the `command` that you give to the container.
propagateTagsbooleanpropagate_tagsboolpropagateTagsBooleanPropagateTagsboolPropagateTags*bool#
Whether to propagate tags from the JobDefinition to the ECS task that Batch spawns.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
retryAttemptsnumberretry_attemptsint | floatretryAttemptsNumberRetryAttemptsdoubleRetryAttempts*float64#
The number of times to retry a job.

The job is retried on failure the same number of attempts as the value.

retryStrategiesRetryStrategy[]retry_strategiestyping.List[RetryStrategy]retryStrategiesList<RetryStrategy>RetryStrategiesRetryStrategy[]RetryStrategies*[]RetryStrategyrequired#
Defines the retry behavior for this job.
schedulingPrioritynumberscheduling_priorityint | floatschedulingPriorityNumberSchedulingPrioritydoubleSchedulingPriority*float64#
The priority of this Job.

Only used in Fairshare Scheduling to decide which job to run first when there are multiple jobs with the same share identifier.

skipDeregisterOnUpdatebooleanskip_deregister_on_updateboolskipDeregisterOnUpdateBooleanSkipDeregisterOnUpdateboolSkipDeregisterOnUpdate*bool= undefined - AWS Batch default is…#
Specifies whether the previous revision of the job definition is retained in an active status after UPDATE events for the resource.
default

Default: undefined - AWS Batch default is false

stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
timeoutDurationtimeoutDurationtimeoutDurationTimeoutDurationTimeoutDuration#
The timeout time for jobs that are submitted with this job definition.

After the amount of time you specify passes, Batch terminates your jobs if they aren't finished.

Methods ​

addRetryStrategy(strategy: RetryStrategy): voiddef add_retry_strategy(self, strategy: RetryStrategy) -> Nonepublic void addRetryStrategy(RetryStrategy strategy)public void AddRetryStrategy(RetryStrategy strategy)func AddRetryStrategy(Strategy RetryStrategy)#
Add a RetryStrategy to this JobDefinition.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

fromJobDefinitionArn(scope: Construct, id: string, jobDefinitionArn: string): IJobDefinition@staticmethod def from_job_definition_arn(scope: Construct, id: str, job_definition_arn: str) -> IJobDefinitionpublic static IJobDefinition fromJobDefinitionArn(Construct scope, String id, String jobDefinitionArn)public static IJobDefinition FromJobDefinitionArn(Construct scope, string id, string jobDefinitionArn)func FromJobDefinitionArn(Scope Construct, Id *string, JobDefinitionArn *string) IJobDefinitionstatic#
Import a JobDefinition by its arn.
grantSubmitJob(identity: IGrantable, queue: IJobQueueRef): voiddef grant_submit_job(self, identity: IGrantable, queue: IJobQueueRef) -> Nonepublic void grantSubmitJob(IGrantable identity, IJobQueueRef queue)public void GrantSubmitJob(IGrantable identity, IJobQueueRef queue)func GrantSubmitJob(Identity IGrantable, Queue IJobQueueRef)#
Grants the `batch:submitJob` permission to the identity on both this job definition and the `queue`.

[disable-awslint:no-grants]

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.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
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.