Bird
0
0

Given this Lambda event handler code snippet triggered by DynamoDB Streams:

medium📝 Predict Output Q13 of 15
AWS - Serverless Architecture
Given this Lambda event handler code snippet triggered by DynamoDB Streams:
def lambda_handler(event, context):
    for record in event['Records']:
        if record['eventName'] == 'INSERT':
            print(record['dynamodb']['NewImage']['id']['S'])

What will this code print when a new item with id '123' is added to the DynamoDB table?
A'123' printed once for the new item
B'id' key printed instead of its value
CAn error because 'NewImage' does not exist
DNothing, because eventName is not 'INSERT'
Step-by-Step Solution
Solution:
  1. Step 1: Understand event structure for INSERT

    For an INSERT event, 'NewImage' contains the new item data including 'id'.
  2. Step 2: Analyze code behavior

    The code prints the string value of 'id' from 'NewImage' when eventName is 'INSERT'.
  3. Final Answer:

    '123' printed once for the new item -> Option A
  4. Quick Check:

    INSERT event prints new id value = D [OK]
Quick Trick: INSERT events have NewImage with new item data [OK]
Common Mistakes:
  • Assuming eventName is different
  • Expecting OldImage on INSERT
  • Confusing key name with value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes