BatchJobProps Struct
Customize the Batch Job Event Target.
| Source | aws-events-targets/lib/batch.ts |
|---|
Example
ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as batch from 'aws-cdk-lib/aws-batch';
import { ContainerImage } from 'aws-cdk-lib/aws-ecs';
declare const vpc: ec2.Vpc;
const computeEnvironment = new batch.FargateComputeEnvironment(this, 'ComputeEnv', {
vpc,
});
const jobQueue = new batch.JobQueue(this, 'JobQueue', {
priority: 1,
computeEnvironments: [
{
computeEnvironment,
order: 1,
},
],
});
const jobDefinition = new batch.EcsJobDefinition(this, 'MyJob', {
container: new batch.EcsEc2ContainerDefinition(this, 'Container', {
image: ecs.ContainerImage.fromRegistry('test-repo'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
}),
});
const queue = new sqs.Queue(this, 'Queue');
const rule = new events.Rule(this, 'Rule', {
schedule: events.Schedule.rate(Duration.hours(1)),
});
rule.addTarget(new targets.BatchJob(
jobQueue.jobQueueArn,
jobQueue,
jobDefinition.jobDefinitionArn,
jobDefinition,
{
deadLetterQueue: queue,
event: events.RuleTargetInput.fromObject({ SomeParam: 'SomeValue' }),
retryAttempts: 2,
maxEventAge: Duration.hours(2),
},
));
python
import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_ecs as ecs
import aws_cdk.aws_batch as batch
from aws_cdk.aws_ecs import ContainerImage
# vpc: ec2.Vpc
compute_environment = batch.FargateComputeEnvironment(self, "ComputeEnv",
vpc=vpc
)
job_queue = batch.JobQueue(self, "JobQueue",
priority=1,
compute_environments=[batch.OrderedComputeEnvironment(
compute_environment=compute_environment,
order=1
)
]
)
job_definition = batch.EcsJobDefinition(self, "MyJob",
container=batch.EcsEc2ContainerDefinition(self, "Container",
image=ecs.ContainerImage.from_registry("test-repo"),
memory=cdk.Size.mebibytes(2048),
cpu=256
)
)
queue = sqs.Queue(self, "Queue")
rule = events.Rule(self, "Rule",
schedule=events.Schedule.rate(Duration.hours(1))
)
rule.add_target(targets.BatchJob(job_queue.job_queue_arn, job_queue, job_definition.job_definition_arn, job_definition,
dead_letter_queue=queue,
event=events.RuleTargetInput.from_object({"SomeParam": "SomeValue"}),
retry_attempts=2,
max_event_age=Duration.hours(2)
))
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.ecs.*;
import software.amazon.awscdk.services.batch.*;
import software.amazon.awscdk.services.ecs.ContainerImage;
Vpc vpc;
FargateComputeEnvironment computeEnvironment = FargateComputeEnvironment.Builder.create(this, "ComputeEnv")
.vpc(vpc)
.build();
JobQueue jobQueue = JobQueue.Builder.create(this, "JobQueue")
.priority(1)
.computeEnvironments(List.of(OrderedComputeEnvironment.builder()
.computeEnvironment(computeEnvironment)
.order(1)
.build()))
.build();
EcsJobDefinition jobDefinition = EcsJobDefinition.Builder.create(this, "MyJob")
.container(EcsEc2ContainerDefinition.Builder.create(this, "Container")
.image(ContainerImage.fromRegistry("test-repo"))
.memory(Size.mebibytes(2048))
.cpu(256)
.build())
.build();
Queue queue = new Queue(this, "Queue");
Rule rule = Rule.Builder.create(this, "Rule")
.schedule(Schedule.rate(Duration.hours(1)))
.build();
rule.addTarget(BatchJob.Builder.create(jobQueue.getJobQueueArn(), jobQueue, jobDefinition.getJobDefinitionArn(), jobDefinition)
.deadLetterQueue(queue)
.event(RuleTargetInput.fromObject(Map.of("SomeParam", "SomeValue")))
.retryAttempts(2)
.maxEventAge(Duration.hours(2))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.ECS;
using Amazon.CDK.AWS.Batch;
Vpc vpc;
var computeEnvironment = new FargateComputeEnvironment(this, "ComputeEnv", new FargateComputeEnvironmentProps {
Vpc = vpc
});
var jobQueue = new JobQueue(this, "JobQueue", new JobQueueProps {
Priority = 1,
ComputeEnvironments = new [] { new OrderedComputeEnvironment {
ComputeEnvironment = computeEnvironment,
Order = 1
} }
});
var jobDefinition = new EcsJobDefinition(this, "MyJob", new EcsJobDefinitionProps {
Container = new EcsEc2ContainerDefinition(this, "Container", new EcsEc2ContainerDefinitionProps {
Image = ContainerImage.FromRegistry("test-repo"),
Memory = Size.Mebibytes(2048),
Cpu = 256
})
});
var queue = new Queue(this, "Queue");
var rule = new Rule(this, "Rule", new RuleProps {
Schedule = Schedule.Rate(Duration.Hours(1))
});
rule.AddTarget(new BatchJob(jobQueue.JobQueueArn, jobQueue, jobDefinition.JobDefinitionArn, jobDefinition, new BatchJobProps {
DeadLetterQueue = queue,
Event = RuleTargetInput.FromObject(new Dictionary<string, string> { { "SomeParam", "SomeValue" } }),
RetryAttempts = 2,
MaxEventAge = Duration.Hours(2)
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import ecs "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc
computeEnvironment := batch.NewFargateComputeEnvironment(this, jsii.String("ComputeEnv"), &FargateComputeEnvironmentProps{
Vpc: Vpc,
})
jobQueue := batch.NewJobQueue(this, jsii.String("JobQueue"), &JobQueueProps{
Priority: jsii.Number(1),
ComputeEnvironments: []OrderedComputeEnvironment{
&OrderedComputeEnvironment{
ComputeEnvironment: *ComputeEnvironment,
Order: jsii.Number(1),
},
},
})
jobDefinition := batch.NewEcsJobDefinition(this, jsii.String("MyJob"), &EcsJobDefinitionProps{
Container: batch.NewEcsEc2ContainerDefinition(this, jsii.String("Container"), &EcsEc2ContainerDefinitionProps{
Image: ecs.ContainerImage_FromRegistry(jsii.String("test-repo")),
Memory: cdk.Size_Mebibytes(jsii.Number(2048)),
Cpu: jsii.Number(256),
}),
})
queue := sqs.NewQueue(this, jsii.String("Queue"))
rule := events.NewRule(this, jsii.String("Rule"), &RuleProps{
Schedule: events.Schedule_Rate(awscdk.Duration_Hours(jsii.Number(1))),
})
rule.AddTarget(targets.NewBatchJob(jobQueue.jobQueueArn, jobQueue, jobDefinition.jobDefinitionArn, jobDefinition, &BatchJobProps{
DeadLetterQueue: queue,
Event: events.RuleTargetInput_FromObject(map[string]*string{
"SomeParam": jsii.String("SomeValue"),
}),
RetryAttempts: jsii.Number(2),
MaxEventAge: awscdk.Duration_*Hours(jsii.Number(2)),
}))
Properties
attemptsoptionalnumberattemptsoptionalint | floatattemptsoptionalNumberAttemptsoptionaldoubleAttemptsoptional*float64 #The number of times to attempt to retry, if the job fails.
Default: no retryStrategy is set
Valid values are 1–10.
deadLetterQueueoptionalIQueuedead_letter_queueoptionalIQueuedeadLetterQueueoptionalIQueueDeadLetterQueueoptionalIQueueDeadLetterQueueoptionalIQueue #The SQS queue to be used as deadLetterQueue. Check out the considerations for using a dead-letter queue.
Default: no dead-letter queue
notes
The events not successfully delivered are automatically retried for a specified period of time, depending on the retry policy of the target. If an event is not delivered before all retry attempts are exhausted, it will be sent to the dead letter queue.
eventoptionalRuleTargetInputeventoptionalRuleTargetInputeventoptionalRuleTargetInputEventoptionalRuleTargetInputEventoptionalRuleTargetInput #The event to send to the Lambda.
Default: the entire EventBridge event
This will be the payload sent to the Lambda Function.
jobNameoptionalstringjob_nameoptionalstrjobNameoptionalStringJobNameoptionalstringJobNameoptional*string #The name of the submitted job.
Default: Automatically generated
maxEventAgeoptionalDurationmax_event_ageoptionalDurationmaxEventAgeoptionalDurationMaxEventAgeoptionalDurationMaxEventAgeoptionalDuration = Duration.hours(24) #The maximum age of a request that Lambda sends to a function for processing.
Minimum value of 60. Maximum value of 86400.
retryAttemptsoptionalnumberretry_attemptsoptionalint | floatretryAttemptsoptionalNumberRetryAttemptsoptionaldoubleRetryAttemptsoptional*float64 = 185 #The maximum number of times to retry when the function returns an error.
Minimum value of 0. Maximum value of 185.
The size of the array, if this is an array batch job.
Default: no arrayProperties are set
Valid values are integers between 2 and 10,000.