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: ```ts import * as sqs from 'aws-cdk-lib/aws-sqs'; import * as eventsources from 'aws-cdk-lib/aws-lambda-event-sources'; declare const handler: lambda.Function; declare const queue: sqs.Queue; handler.addEventSource(new eventsources.SqsEventSource(queue)); ``` 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.
import { EventSourceMapping } from 'aws-cdk-lib/aws-lambda';Or use the module namespace:
import * as lambda from 'aws-cdk-lib/aws-lambda';
// lambda.EventSourceMappingConfiguration passed to the constructor as EventSourceMappingProps.
targetRequiredIFunctionThe target AWS Lambda function.
EventSourceMappingOptionsbatchSizeOptionalinherited from EventSourceMappingOptionsnumberThe 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.
The default for Amazon SQS is 10 messages. For standard SQS queues, the maximum is 10,000. For FIFO SQS queues, the maximum is 10.
bisectBatchOnErrorOptionalinherited from EventSourceMappingOptionsbooleanIf the function returns an error, split the batch in two and retry.
Default: false
enabledOptionalinherited from EventSourceMappingOptionsbooleanSet to false to disable the event source upon creation.
Default: true
eventSourceArnOptionalinherited from EventSourceMappingOptionsstringThe Amazon Resource Name (ARN) of the event source. Any record added to this stream can invoke the Lambda function.
Default: - not set if using a self managed Kafka cluster, throws an error otherwise
filterEncryptionOptionalinherited from EventSourceMappingOptionsIKeyAdd Customer managed KMS key to encrypt Filter Criteria.
Default: - none
filtersOptionalinherited from EventSourceMappingOptions{ [key: string]: any }[]Add filter criteria to Event Source.
Default: - none
kafkaBootstrapServersOptionalinherited from EventSourceMappingOptionsstring[]A list of host and port pairs that are the addresses of the Kafka brokers in a self managed "bootstrap" Kafka cluster that a Kafka client connects to initially to bootstrap itself. They are in the format `abc.example.com:9096`.
Default: - none
kafkaConsumerGroupIdOptionalinherited from EventSourceMappingOptionsstringThe identifier for the Kafka consumer group to join. The consumer group ID must be unique among all your Kafka event sources. After creating a Kafka event source mapping with the consumer group ID specified, you cannot update this value. The value must have a length between 1 and 200 and full the pattern '[a-zA-Z0-9-\/*:_+=.@-]*'. For more information, see [Customizable consumer group ID](https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html#services-msk-consumer-group-id).
Default: - none
kafkaTopicOptionalinherited from EventSourceMappingOptionsstringThe name of the Kafka topic.
Default: - no topic
logLevelOptionalinherited from EventSourceMappingOptionsEventSourceMappingLogLevelConfiguration for logging verbosity from the event source mapping poller. This configuration controls the verbosity of the logs generated by the polling infrastructure that reads events from the event source. The logs provide insights into the internal operations of the event source mapping, including connection status, polling behavior, and error conditions.
Default: - No logging
maxBatchingWindowOptionalinherited from EventSourceMappingOptionsDurationThe maximum amount of time to gather records before invoking the function. Maximum of Duration.minutes(5)
Default: Duration.seconds(0)
maxConcurrencyOptionalinherited from EventSourceMappingOptionsnumberThe maximum concurrency setting limits the number of concurrent instances of the function that an Amazon SQS event source can invoke.
Default: - No specific limit.
maxRecordAgeOptionalinherited from EventSourceMappingOptionsDurationThe 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.
metricsConfigOptionalinherited from EventSourceMappingOptionsMetricsConfigConfiguration for enhanced monitoring metrics collection When specified, enables collection of additional metrics for the stream event source.
Default: - Enhanced monitoring is disabled
onFailureOptionalinherited from EventSourceMappingOptionsIEventSourceDlqAn Amazon S3, Amazon SQS queue or Amazon SNS topic destination for discarded records.
Default: discarded records are ignored
parallelizationFactorOptionalinherited from EventSourceMappingOptionsnumberThe number of batches to process from each shard concurrently. Valid Range: * Minimum value of 1 * Maximum value of 10
Default: 1
provisionedPollerConfigOptionalinherited from EventSourceMappingOptionsProvisionedPollerConfigConfiguration for provisioned pollers that read from the event source. When specified, allows control over the minimum and maximum number of pollers that can be provisioned to process events from the source.
Default: - no provisioned pollers
reportBatchItemFailuresOptionalinherited from EventSourceMappingOptionsbooleanAllow functions to return partially successful responses for a batch of records.
Default: false
retryAttemptsOptionalinherited from EventSourceMappingOptionsnumberThe 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.
schemaRegistryConfigOptionalinherited from EventSourceMappingOptionsISchemaRegistrySpecific configuration settings for a Kafka schema registry.
Default: - none
sourceAccessConfigurationsOptionalinherited from EventSourceMappingOptionsSourceAccessConfiguration[]Specific settings like the authentication protocol or the VPC components to secure access to your event source.
Default: - none
startingPositionOptionalinherited from EventSourceMappingOptionsStartingPositionThe position in the DynamoDB, Kinesis or MSK stream where AWS Lambda should start reading.
Default: - no starting position
startingPositionTimestampOptionalinherited from EventSourceMappingOptionsnumberThe time from which to start reading, in Unix time seconds.
Default: - no timestamp
supportS3OnFailureDestinationOptionalinherited from EventSourceMappingOptionsbooleanCheck if support S3 onfailure destination(OFD). Kinesis, DynamoDB, MSK and self managed kafka event support S3 OFD
Default: false
tumblingWindowOptionalinherited from EventSourceMappingOptionsDurationThe size of the tumbling windows to group records sent to DynamoDB or Kinesis.
Default: - None
Everything you need to know about AWS Lambda on one page. HD quality, print-friendly.
Download Free Infographicaws-lambda