aws-cdk-lib.aws_events_targets.BatchJobProps

interface BatchJobProps

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

Customize the Batch Job Event Target.

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

Properties

NameTypeDescription
attempts?numberThe number of times to attempt to retry, if the job fails.
deadLetterQueue?IQueueThe SQS queue to be used as deadLetterQueue. Check out the considerations for using a dead-letter queue.
event?RuleTargetInputThe event to send to the Lambda.
jobName?stringThe name of the submitted job.
maxEventAge?DurationThe maximum age of a request that Lambda sends to a function for processing.
retryAttempts?numberThe maximum number of times to retry when the function returns an error.
size?numberThe size of the array, if this is an array batch job.

attempts?

Type: number (optional, default: no retryStrategy is set)

The number of times to attempt to retry, if the job fails.

Valid values are 1–10.


deadLetterQueue?

Type: IQueue (optional, default: no dead-letter queue)

The SQS queue to be used as deadLetterQueue. Check out the considerations for using a dead-letter queue.

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.


event?

Type: RuleTargetInput (optional, default: the entire EventBridge event)

The event to send to the Lambda.

This will be the payload sent to the Lambda Function.


jobName?

Type: string (optional, default: Automatically generated)

The name of the submitted job.


maxEventAge?

Type: Duration (optional, default: 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.


retryAttempts?

Type: number (optional, default: 185)

The maximum number of times to retry when the function returns an error.

Minimum value of 0. Maximum value of 185.


size?

Type: number (optional, default: no arrayProperties are set)

The size of the array, if this is an array batch job.

Valid values are integers between 2 and 10,000.