aws-cdk-lib.aws_events_targets.BatchJob

class BatchJob

LanguageType name
.NETAmazon.CDK.AWS.Events.Targets.BatchJob
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awseventstargets#BatchJob
Javasoftware.amazon.awscdk.services.events.targets.BatchJob
Pythonaws_cdk.aws_events_targets.BatchJob
TypeScript (source)aws-cdk-lib » aws_events_targets » BatchJob

Implements IRuleTarget

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/aws-batch-alpha';
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 BatchJobProps

Methods

NameDescription
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

  • RuleTargetConfig

Returns a RuleTarget that can be used to trigger queue this batch job as a result from an EventBridge event.