class BatchJob
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.Events.Targets.BatchJob |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awseventstargets#BatchJob |
Java | software.amazon.awscdk.services.events.targets.BatchJob |
Python | aws_cdk.aws_events_targets.BatchJob |
TypeScript (source) | aws-cdk-lib » aws_events_targets » BatchJob |
Implements
IRule
Use an AWS Batch Job / Queue as an event rule target.
Most likely the code will look something like this:
new BatchJob(jobQueue.jobQueueArn, jobQueue, jobDefinition.jobDefinitionArn, jobDefinition)
In the future this API will be improved to be fully typed
Example
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),
},
));
Initializer
new BatchJob(jobQueueArn: string, jobQueueScope: IConstruct, jobDefinitionArn: string, jobDefinitionScope: IConstruct, props?: BatchJobProps)
Parameters
- jobQueueArn
string
— The JobQueue arn. - jobQueueScope
IConstruct
— The JobQueue Resource. - jobDefinitionArn
string
— The jobDefinition arn. - jobDefinitionScope
IConstruct
— The JobQueue Resource. - props
Batch
Job Props
Methods
Name | Description |
---|---|
bind(rule, _id?) | Returns a RuleTarget that can be used to trigger queue this batch job as a result from an EventBridge event. |
bind(rule, _id?)
public bind(rule: IRule, _id?: string): RuleTargetConfig
Parameters
- rule
IRule
- _id
string
Returns
Returns a RuleTarget that can be used to trigger queue this batch job as a result from an EventBridge event.