Wire an Event Source to a Function
A 3-step recipe with AWS Lambda. We can help you get access.
Recipe · 3 steps
Wire an Event Source to a Function
with AWS Lambda · IT Infrastructure Management
Create an event source mapping and wait for it to reach the Enabled state.
- Confirm the consuming function exists and capture its ARN before any mapping is created, so a bad function name fails here rather than leaving a mapping pointed at nothing.
- Map the event source onto the function. Enabled is true so Lambda begins polling as soon as the mapping is ready, and failure handling is set here rather than left to defaults so a poison record cannot stall the source indefinitely.
- Poll the mapping until Lambda reports State "Enabled". The create call returns while the state is still "Creating", and no records are read from the event source until the mapping is enabled.
What you'll need to have ready
- functionName: The name, ARN, or partial ARN of the function that consumes the events.
- eventSourceArn: The ARN of the event source (SQS queue, Kinesis stream, DynamoDB stream, MSK cluster, or DocumentDB change stream).
- batchSize: Maximum number of records delivered to the function in a single invocation.
- maximumBatchingWindowInSeconds: How long Lambda waits to gather a full batch before invoking with a partial one.
- startingPosition: Where to begin reading a stream — TRIM_HORIZON for the oldest record, LATEST for new records only, or AT_TIMESTAMP. Required for Kinesis, DynamoDB Streams, and
- maximumRetryAttempts: Retries before a stream record batch is discarded or sent on-failure.
- bisectBatchOnFunctionError: Split a failing batch in two and retry each half, isolating the poison record.
- onFailureDestinationArn: ARN of the SQS queue or SNS topic that receives records Lambda could not process.
- functionResponseTypes: Set to ["ReportBatchItemFailures"] to let the handler return only the records that failed.
For your developer
Arazzo workflow aws-lambda:event-source-mapping-onboard, 3 operations: GetFunction → CreateEventSourceMapping → GetEventSourceMapping. Specs on APIs.io.