BatchJob

class aws_cdk.aws_events_targets.BatchJob(job_queue_arn, job_queue_scope, job_definition_arn, job_definition_scope, *, attempts=None, event=None, job_name=None, size=None, dead_letter_queue=None, max_event_age=None, retry_attempts=None)

Bases: object

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

ExampleMetadata:

infused

Example:

import aws_cdk.aws_batch as batch
from aws_cdk.aws_ecs import ContainerImage


job_queue = batch.JobQueue(self, "MyQueue",
    compute_environments=[batch.JobQueueComputeEnvironment(
        compute_environment=batch.ComputeEnvironment(self, "ComputeEnvironment",
            managed=False
        ),
        order=1
    )
    ]
)

job_definition = batch.JobDefinition(self, "MyJob",
    container=batch.JobDefinitionContainer(
        image=ContainerImage.from_registry("test-repo")
    )
)

queue = sqs.Queue(self, "Queue")

rule = events.Rule(self, "Rule",
    schedule=events.Schedule.rate(cdk.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=cdk.Duration.hours(2)
))
Parameters:
  • job_queue_arn (str) – The JobQueue arn.

  • job_queue_scope (IConstruct) – The JobQueue Resource.

  • job_definition_arn (str) – The jobDefinition arn.

  • job_definition_scope (IConstruct) – The JobQueue Resource.

  • attempts (Union[int, float, None]) – The number of times to attempt to retry, if the job fails. Valid values are 1–10. Default: no retryStrategy is set

  • event (Optional[RuleTargetInput]) – The event to send to the Lambda. This will be the payload sent to the Lambda Function. Default: the entire EventBridge event

  • job_name (Optional[str]) – The name of the submitted job. Default: - Automatically generated

  • size (Union[int, float, None]) – The size of the array, if this is an array batch job. Valid values are integers between 2 and 10,000. Default: no arrayProperties are set

  • dead_letter_queue (Optional[IQueue]) – 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. Default: - no dead-letter queue

  • max_event_age (Optional[Duration]) – The maximum age of a request that Lambda sends to a function for processing. Minimum value of 60. Maximum value of 86400. Default: Duration.hours(24)

  • retry_attempts (Union[int, float, None]) – The maximum number of times to retry when the function returns an error. Minimum value of 0. Maximum value of 185. Default: 185

Methods

bind(rule, _id=None)

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

Parameters:
  • rule (IRule) –

  • _id (Optional[str]) –

Return type:

RuleTargetConfig