Skip to content
v2.274.0

JobQueue L2 construct ​

JobQueues can receive Jobs, which are removed from the queue when sent to the linked ComputeEnvironment(s) to be executed.

Jobs exit the queue in FIFO order unless a SchedulingPolicy is linked.

Example ​

ts
declare const vpc: ec2.IVpc;

const ecsJob = 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,
  }),
});

const queue = new batch.JobQueue(this, 'JobQueue', {
  computeEnvironments: [{
    computeEnvironment: new batch.ManagedEc2EcsComputeEnvironment(this, 'managedEc2CE', {
      vpc,
    }),
    order: 1,
  }],
  priority: 10,
});

const user = new iam.User(this, 'MyUser');
ecsJob.grantSubmitJob(user, queue);
python
# vpc: ec2.IVpc


ecs_job = 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
    )
)

queue = batch.JobQueue(self, "JobQueue",
    compute_environments=[batch.OrderedComputeEnvironment(
        compute_environment=batch.ManagedEc2EcsComputeEnvironment(self, "managedEc2CE",
            vpc=vpc
        ),
        order=1
    )],
    priority=10
)

user = iam.User(self, "MyUser")
ecs_job.grant_submit_job(user, queue)
java
IVpc vpc;


EcsJobDefinition ecsJob = 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)
                .build())
        .build();

JobQueue queue = JobQueue.Builder.create(this, "JobQueue")
        .computeEnvironments(List.of(OrderedComputeEnvironment.builder()
                .computeEnvironment(ManagedEc2EcsComputeEnvironment.Builder.create(this, "managedEc2CE")
                        .vpc(vpc)
                        .build())
                .order(1)
                .build()))
        .priority(10)
        .build();

User user = new User(this, "MyUser");
ecsJob.grantSubmitJob(user, queue);
csharp
// Install: dotnet add package Amazon.CDK.Lib
IVpc vpc;


var ecsJob = 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
    })
});

var queue = new JobQueue(this, "JobQueue", new JobQueueProps {
    ComputeEnvironments = new [] { new OrderedComputeEnvironment {
        ComputeEnvironment = new ManagedEc2EcsComputeEnvironment(this, "managedEc2CE", new ManagedEc2EcsComputeEnvironmentProps {
            Vpc = vpc
        }),
        Order = 1
    } },
    Priority = 10
});

var user = new User(this, "MyUser");
ecsJob.GrantSubmitJob(user, queue);
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc IVpc


ecsJob := 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),
	}),
})

queue := batch.NewJobQueue(this, jsii.String("JobQueue"), &JobQueueProps{
	ComputeEnvironments: []OrderedComputeEnvironment{
		&OrderedComputeEnvironment{
			ComputeEnvironment: batch.NewManagedEc2EcsComputeEnvironment(this, jsii.String("managedEc2CE"), &ManagedEc2EcsComputeEnvironmentProps{
				Vpc: *Vpc,
			}),
			Order: jsii.Number(1),
		},
	},
	Priority: jsii.Number(10),
})

user := iam.NewUser(this, jsii.String("MyUser"))
ecsJob.GrantSubmitJob(user, queue)

Initializer ​

ts
new JobQueue(scope: Construct, id: string, props?: JobQueueProps)
python
JobQueue(scope: Construct, id: str, props: typing.Optional[JobQueueProps] = None)
java
new JobQueue(Construct scope, String id, JobQueueProps props)
csharp
new JobQueue(Construct scope, string id, JobQueueProps? props = null)
go
NewJobQueue(Scope Construct, Id *string, Props JobQueueProps)

Construct Props ​

computeEnvironmentsOrderedComputeEnvironment[]compute_environmentstyping.List[OrderedComputeEnvironment]computeEnvironmentsList<OrderedComputeEnvironment>ComputeEnvironmentsOrderedComputeEnvironment[]ComputeEnvironments*[]OrderedComputeEnvironment= none#
The set of compute environments mapped to a job queue and their order relative to each other.
notes

The job scheduler uses this parameter to determine which compute environment runs a specific job. Compute environments must be in the VALID state before you can associate them with a job queue. You can associate up to three compute environments with a job queue. All of the compute environments must be either EC2 (EC2 or SPOT) or Fargate (FARGATE or FARGATE_SPOT); EC2 and Fargate compute environments can't be mixed.

Note: All compute environments that are associated with a job queue must share the same architecture. AWS Batch doesn't support mixing compute environment architecture types in a single job queue.

enabledbooleanenabledboolenabledBooleanEnabledboolEnabled*bool= true#
If the job queue is enabled, it is able to accept jobs.

Otherwise, new jobs can't be added to the queue, but jobs already in the queue can finish.

jobQueueNamestringjob_queue_namestrjobQueueNameStringJobQueueNamestringJobQueueName*string= no name#
The name of the job queue.

It can be up to 128 letters long. It can contain uppercase and lowercase letters, numbers, hyphens (-), and underscores (_)

jobStateTimeLimitActionsJobStateTimeLimitAction[]job_state_time_limit_actionstyping.List[JobStateTimeLimitAction]jobStateTimeLimitActionsList<JobStateTimeLimitAction>JobStateTimeLimitActionsJobStateTimeLimitAction[]JobStateTimeLimitActions*[]JobStateTimeLimitAction= no actions#
The set of actions that AWS Batch perform on jobs that remain at the head of the job queue in the specified state longer than specified times.
prioritynumberpriorityint | floatpriorityNumberPrioritydoublePriority*float64= 1#
The priority of the job queue.
notes

Job queues with a higher priority are evaluated first when associated with the same compute environment. Priority is determined in descending order. For example, a job queue with a priority of 10 is given scheduling preference over a job queue with a priority of 1.

schedulingPolicyISchedulingPolicyRefscheduling_policyISchedulingPolicyRefschedulingPolicyISchedulingPolicyRefSchedulingPolicyISchedulingPolicyRefSchedulingPolicyISchedulingPolicyRef= no scheduling policy#
The SchedulingPolicy for this JobQueue.

Instructs the Scheduler how to schedule different jobs.

Properties ​

computeEnvironmentsOrderedComputeEnvironment[]compute_environmentstyping.List[OrderedComputeEnvironment]computeEnvironmentsList<OrderedComputeEnvironment>ComputeEnvironmentsOrderedComputeEnvironment[]ComputeEnvironments*[]OrderedComputeEnvironmentrequired#
The set of compute environments mapped to a job queue and their order relative to each other.
notes

The job scheduler uses this parameter to determine which compute environment runs a specific job. Compute environments must be in the VALID state before you can associate them with a job queue. You can associate up to three compute environments with a job queue. All of the compute environments must be either EC2 (EC2 or SPOT) or Fargate (FARGATE or FARGATE_SPOT); EC2 and Fargate compute environments can't be mixed.

Note: All compute environments that are associated with a job queue must share the same architecture. AWS Batch doesn't support mixing compute environment architecture types in a single job queue.

enabledbooleanenabledboolenabledBooleanEnabledboolEnabled*bool#
If the job queue is enabled, it is able to accept jobs.

Otherwise, new jobs can't be added to the queue, but jobs already in the queue can finish.

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.

jobQueueArnstringjob_queue_arnstrjobQueueArnStringJobQueueArnstringJobQueueArn*stringrequired#
The ARN of this job queue.
jobQueueNamestringjob_queue_namestrjobQueueNameStringJobQueueNamestringJobQueueName*stringrequired#
The name of the job queue.

It can be up to 128 letters long. It can contain uppercase and lowercase letters, numbers, hyphens (-), and underscores (_)

jobQueueRefJobQueueReferencejob_queue_refJobQueueReferencejobQueueRefJobQueueReferenceJobQueueRefJobQueueReferenceJobQueueRefJobQueueReferencerequired#
A reference to a JobQueue resource.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
prioritynumberpriorityint | floatpriorityNumberPrioritydoublePriority*float64required#
The priority of the job queue.
notes

Job queues with a higher priority are evaluated first when associated with the same compute environment. Priority is determined in descending order. For example, a job queue with a priority value of 10 is given scheduling preference over a job queue with a priority value of 1.

PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
schedulingPolicyISchedulingPolicyscheduling_policyISchedulingPolicyschedulingPolicyISchedulingPolicySchedulingPolicyISchedulingPolicySchedulingPolicyISchedulingPolicy#
The SchedulingPolicy for this JobQueue.

Instructs the Scheduler how to schedule different jobs.

stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.

Methods ​

addComputeEnvironment(computeEnvironment: IComputeEnvironmentRef, order: number): voiddef add_compute_environment(self, compute_environment: IComputeEnvironmentRef, order: int | float) -> Nonepublic void addComputeEnvironment(IComputeEnvironmentRef computeEnvironment, Number order)public void AddComputeEnvironment(IComputeEnvironmentRef computeEnvironment, double order)func AddComputeEnvironment(ComputeEnvironment IComputeEnvironmentRef, Order *float64)#
Add a `ComputeEnvironment` to this Queue.

The Queue will prefer lower-order ComputeEnvironments.

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).

fromJobQueueArn(scope: Construct, id: string, jobQueueArn: string): IJobQueue@staticmethod def from_job_queue_arn(scope: Construct, id: str, job_queue_arn: str) -> IJobQueuepublic static IJobQueue fromJobQueueArn(Construct scope, String id, String jobQueueArn)public static IJobQueue FromJobQueueArn(Construct scope, string id, string jobQueueArn)func FromJobQueueArn(Scope Construct, Id *string, JobQueueArn *string) IJobQueuestatic#
refer to an existing JobQueue by its arn.
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.