0
0
DynamoDBquery~10 mins

Lambda trigger on stream events in DynamoDB - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Lambda trigger on stream events
DynamoDB Table Update
Stream Records Created
Lambda Triggered
Lambda Processes Records
Lambda Executes Business Logic
Optional: Write Back to DB or Other Service
When a DynamoDB table changes, a stream record is created. This triggers a Lambda function that processes the record and runs your code.
Execution Sample
DynamoDB
1. Update DynamoDB item
2. Stream captures change
3. Lambda triggered with event
4. Lambda reads event records
5. Lambda processes each record
Shows how a DynamoDB update triggers a Lambda function via stream events.
Execution Table
StepEvent SourceActionLambda InputLambda Output
1DynamoDB TableItem updatedN/AN/A
2DynamoDB StreamStream record createdRecord with change infoN/A
3Lambda ServiceLambda triggeredEvent with stream recordsN/A
4Lambda FunctionReads event recordsStream records arrayParsed records
5Lambda FunctionProcesses each recordSingle recordBusiness logic result
6Lambda FunctionCompletes executionN/ASuccess or error logged
7EndNo more recordsN/ALambda idle until next event
💡 No more stream records to process, Lambda waits for next trigger
Variable Tracker
VariableStartAfter Step 2After Step 4After Step 5Final
streamRecordsemptycontains 1 recordparsed 1 recordprocessed 1 recordempty after processing
lambdaEventnonenoneevent with recordsevent processednone
Key Moments - 2 Insights
Why does Lambda receive an event with multiple records sometimes?
Because DynamoDB streams batch multiple changes before triggering Lambda, as seen in execution_table step 3 and 4 where Lambda input is an event with an array of records.
What happens if Lambda fails to process a record?
Lambda logs an error and may retry depending on configuration. This is implied in execution_table step 6 where Lambda completes execution with success or error logged.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does Lambda first receive the stream event?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Check the 'Lambda Input' column to see when Lambda is triggered with the event
According to variable_tracker, what is the state of 'streamRecords' after Lambda processes each record?
Aparsed 1 record
Bcontains 1 record
Cempty after processing
Dnone
💡 Hint
Look at the 'After Step 5' and 'Final' columns for 'streamRecords'
If multiple items update quickly, how does Lambda receive the events?
ABatch of records in one event
BNo events triggered
COne event per item update
DOnly last update triggers event
💡 Hint
Refer to key_moments explanation about batching and execution_table steps 3 and 4
Concept Snapshot
Lambda triggers on DynamoDB stream events when table data changes.
Stream batches changes and sends records to Lambda.
Lambda receives event with array of records.
Lambda processes each record in order.
Errors can cause retries.
Useful for real-time processing of DB changes.
Full Transcript
When you update a DynamoDB table, the change creates a stream record. This stream record triggers a Lambda function. The Lambda function receives an event containing one or more stream records. It reads and processes each record, running your business logic. After processing, Lambda finishes and waits for the next trigger. Sometimes multiple changes batch into one event, so Lambda handles multiple records at once. If Lambda fails, it logs errors and may retry. This setup lets you react instantly to database changes with your code.