Event Source Mapping in AWS Lambda
Instruction: Describe what event source mapping is in the context of AWS Lambda and provide examples of when it might be used.
Updated
Official answer
An event source mapping is a Lambda resource that reads a supported queue or stream and invokes a function with records. Examples include SQS, Kinesis and an enabled DynamoDB stream. This differs from a service such as S3 pushing an asynchronous event directly to Lambda.
Configure the source ARN, function version or alias, permissions, batch size, batching window and applicable concurrency/failure settings. For streams, choose the starting position and understand retention. For a DynamoDB table, enable the required stream view and reference the stream, not the ordinary table ARN.
The handler must process a batch, which can contain one or many records. Delivery can occur more than once. For SQS, successful processing permits message deletion; failure can cause redelivery after visibility timeout. With supported partial batch responses enabled, report failed records correctly instead of acknowledging unsuccessful work.
Stream processing uses checkpoints and ordering rules. A poison record can hold up progress; use supported retry, batch-splitting and failure-retention controls. DynamoDB Streams orders changes for each item, not all items globally. Partial batch response details and identifiers differ by source.
For an order-update consumer, test a duplicate, a mixed-success batch, a poison record and a restart. Monitor source backlog or IteratorAge as appropriate, and verify output commitment before reporting success.