EventSourceMapping

class aws_cdk.aws_lambda.EventSourceMapping(scope, id, *, target, event_source_arn, batch_size=None, bisect_batch_on_error=None, enabled=None, kafka_topic=None, max_batching_window=None, max_record_age=None, on_failure=None, parallelization_factor=None, retry_attempts=None, starting_position=None)

Bases: aws_cdk.core.Resource

Defines a Lambda EventSourceMapping resource.

Usually, you won’t need to define the mapping yourself. This will usually be done by event sources. For example, to add an SQS event source to a function:

import { SqsEventSource } from '@aws-cdk/aws-lambda-event-sources';
lambda.addEventSource(new SqsEventSource(sqs));

The SqsEventSource class will automatically create the mapping, and will also modify the Lambda’s execution role so it can consume messages from the queue.

Parameters
  • scope (Construct) –

  • id (str) –

  • target (IFunction) – The target AWS Lambda function.

  • event_source_arn (str) – The Amazon Resource Name (ARN) of the event source. Any record added to this stream can invoke the Lambda function.

  • batch_size (Union[int, float, None]) – The largest number of records that AWS Lambda will retrieve from your event source at the time of invoking your function. Your function receives an event with all the retrieved records. Valid Range: Minimum value of 1. Maximum value of 10000. Default: - Amazon Kinesis, Amazon DynamoDB, and Amazon MSK is 100 records. Both the default and maximum for Amazon SQS are 10 messages.

  • bisect_batch_on_error (Optional[bool]) – If the function returns an error, split the batch in two and retry. Default: false

  • enabled (Optional[bool]) – Set to false to disable the event source upon creation. Default: true

  • kafka_topic (Optional[str]) – The name of the Kafka topic. Default: - no topic

  • max_batching_window (Optional[Duration]) – The maximum amount of time to gather records before invoking the function. Maximum of Duration.minutes(5) Default: Duration.seconds(0)

  • max_record_age (Optional[Duration]) – The maximum age of a record that Lambda sends to a function for processing. Valid Range: - Minimum value of 60 seconds - Maximum value of 7 days Default: - infinite or until the record expires.

  • on_failure (Optional[IEventSourceDlq]) – An Amazon SQS queue or Amazon SNS topic destination for discarded records. Default: discarded records are ignored

  • parallelization_factor (Union[int, float, None]) – The number of batches to process from each shard concurrently. Valid Range: - Minimum value of 1 - Maximum value of 10 Default: 1

  • retry_attempts (Union[int, float, None]) – The maximum number of times to retry when the function returns an error. Set to undefined if you want lambda to keep retrying infinitely or until the record expires. Valid Range: - Minimum value of 0 - Maximum value of 10000 Default: - infinite or until the record expires.

  • starting_position (Optional[StartingPosition]) – The position in the DynamoDB, Kinesis or MSK stream where AWS Lambda should start reading. Default: - Required for Amazon Kinesis, Amazon DynamoDB, and Amazon MSK Streams sources.

Methods

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

Return type

ResourceEnvironment

event_source_mapping_id

The identifier for this EventSourceMapping.

Return type

str

node

The construct tree node associated with this construct.

Return type

ConstructNode

stack

The stack in which this resource is defined.

Return type

Stack

Static Methods

classmethod from_event_source_mapping_id(scope, id, event_source_mapping_id)

Import an event source into this stack from its event source id.

Parameters
  • scope (Construct) –

  • id (str) –

  • event_source_mapping_id (str) –

Return type

IEventSourceMapping

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters

x (Any) –

Return type

bool