What is a Lambda trigger on DynamoDB stream events?
It is a way to automatically run AWS Lambda functions when changes happen in a DynamoDB table, like adding, updating, or deleting items.
Click to reveal answer
beginner
How does DynamoDB Streams help Lambda functions?
DynamoDB Streams captures table activity and sends event records to Lambda, which then processes these changes in near real-time.
Click to reveal answer
beginner
What types of events can trigger a Lambda function from a DynamoDB stream?
INSERT (new item added), MODIFY (item updated), and REMOVE (item deleted) events can trigger Lambda functions.
Click to reveal answer
intermediate
Why use Lambda triggers on DynamoDB streams instead of polling the table?
Lambda triggers respond instantly to changes without constant checking, saving resources and providing faster reactions.
Click to reveal answer
intermediate
What must you enable on a DynamoDB table to use Lambda triggers on stream events?
You must enable DynamoDB Streams on the table and configure the stream to capture the desired data (keys only, new image, old image, or both).
Click to reveal answer
Which DynamoDB stream event type triggers when an item is deleted?
AUPDATE
BMODIFY
CINSERT
DREMOVE
✗ Incorrect
REMOVE events occur when an item is deleted from the table.
What must be enabled on a DynamoDB table to use Lambda triggers on stream events?
ADynamoDB Streams
BAuto Scaling
CGlobal Tables
DBackup and Restore
✗ Incorrect
DynamoDB Streams must be enabled to capture changes and trigger Lambda functions.
Which of the following is NOT a benefit of using Lambda triggers on DynamoDB streams?
AManual polling of the table for changes
BAutomatic scaling of Lambda functions
CReduced resource usage compared to polling
DReal-time processing of data changes
✗ Incorrect
Manual polling is not a benefit; Lambda triggers avoid the need for polling.
What kind of data can DynamoDB Streams capture for Lambda triggers?
AOnly the primary key
BNew item image, old item image, or both
COnly deleted items
DOnly updated attributes
✗ Incorrect
Streams can capture new images, old images, or both depending on configuration.
When a Lambda function is triggered by a DynamoDB stream, what does it receive?
AThe entire DynamoDB table
BOnly the updated attributes
CA batch of event records describing changes
DA snapshot of the database
✗ Incorrect
Lambda receives a batch of event records describing the changes made.
Explain how a Lambda trigger works with DynamoDB stream events.
Think about what happens when data changes in the table.
You got /4 concepts.
List the steps to set up a Lambda trigger on DynamoDB stream events.
Consider both DynamoDB and Lambda configurations.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of a Lambda trigger on DynamoDB stream events?
easy
A. To backup the DynamoDB table data to S3
B. To manually update the DynamoDB table from the Lambda console
C. To disable the DynamoDB stream temporarily
D. To automatically run code when data in the DynamoDB table changes
Solution
Step 1: Understand DynamoDB streams
DynamoDB streams capture data changes like inserts, updates, and deletes.
Step 2: Role of Lambda triggers
Lambda triggers run code automatically when these stream events occur.
Final Answer:
To automatically run code when data in the DynamoDB table changes -> Option D
Quick Check:
Lambda triggers = auto-run code on data change [OK]
Hint: Lambda triggers run code automatically on data changes [OK]
Common Mistakes:
Thinking Lambda triggers require manual execution
Confusing stream enabling with backup
Assuming Lambda disables streams
2. Which of the following is the correct way to specify a Lambda trigger for a DynamoDB stream in AWS Console?
easy
A. Enable stream on the table, then add Lambda as a trigger on the stream
B. Create Lambda function first, then enable stream on the table
C. Enable stream on the table and Lambda separately without linking
D. Add Lambda trigger before enabling the stream on the table
Solution
Step 1: Enable stream on DynamoDB table
Streams must be enabled first to capture data changes.
Step 2: Add Lambda as a trigger on the enabled stream
Lambda triggers are linked to the stream to react to events.
Final Answer:
Enable stream on the table, then add Lambda as a trigger on the stream -> Option A
Quick Check:
Enable stream first, then add Lambda trigger [OK]
Hint: Enable stream first, then attach Lambda trigger [OK]
Common Mistakes:
Trying to add Lambda trigger before enabling stream
Not linking Lambda to the stream
Enabling stream and Lambda separately without connection
3. Given this Lambda function snippet triggered by a DynamoDB stream event:
def lambda_handler(event, context):
for record in event['Records']:
if record['eventName'] == 'INSERT':
print(record['dynamodb']['NewImage']['id']['S'])
What will this code output when a new item with id '123' is inserted?
medium
A. It prints '123' to the logs
B. It prints the old image of the item
C. It raises a KeyError because 'NewImage' is missing
D. It prints nothing because eventName is 'MODIFY'
Solution
Step 1: Check eventName condition
The code checks if eventName is 'INSERT', which matches new item insertion.
Step 2: Access NewImage id value
It accesses 'NewImage' dictionary and prints the 'id' string value '123'.
Final Answer:
It prints '123' to the logs -> Option A
Quick Check:
INSERT event prints new id '123' [OK]
Hint: INSERT event uses NewImage to get new item data [OK]
Common Mistakes:
Confusing NewImage with OldImage
Assuming eventName is MODIFY instead of INSERT
Not accessing nested dictionary keys correctly
4. You wrote this Lambda code to process DynamoDB stream events but it throws a runtime error:
def lambda_handler(event, context):
for record in event['Records']:
print(record['dynamodb']['NewImage']['id']['S'])
What is the likely cause of the error?
medium
A. The 'id' attribute is always an integer, not a string
B. The event may contain DELETE events without NewImage data
C. The event['Records'] key is missing
D. Lambda functions cannot access DynamoDB streams
Solution
Step 1: Understand stream event types
DELETE events do not have 'NewImage', only 'OldImage'.
Step 2: Accessing NewImage without check causes error
Trying to access 'NewImage' on DELETE events causes a KeyError.
Final Answer:
The event may contain DELETE events without NewImage data -> Option B
Hint: Check event type before accessing NewImage [OK]
Common Mistakes:
Assuming all events have NewImage
Ignoring DELETE event structure
Believing Lambda can't access streams
5. You want your Lambda triggered by DynamoDB streams to process only UPDATE events where the attribute 'status' changed to 'completed'. Which approach is best?
hard
A. Filter events in DynamoDB stream settings to only send UPDATE events with 'completed' status
B. Use a separate Lambda for each event type and status value
C. In Lambda, check if eventName is 'MODIFY' and compare OldImage and NewImage 'status' values
D. Enable stream with only KEYS_ONLY to reduce data size
Solution
Step 1: Understand stream filtering limits
DynamoDB streams cannot filter by attribute values, only event types.
Step 2: Use Lambda code to check eventName and compare status
Lambda can check if eventName is 'MODIFY' and compare OldImage and NewImage 'status' to detect change to 'completed'.
Final Answer:
In Lambda, check if eventName is 'MODIFY' and compare OldImage and NewImage 'status' values -> Option C
Quick Check:
Filter in Lambda by event and attribute change [OK]
Hint: Filter attribute changes inside Lambda, not in stream settings [OK]
Common Mistakes:
Trying to filter by attribute in stream settings
Using KEYS_ONLY which lacks attribute data
Creating multiple Lambdas unnecessarily
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.