Bird
0
0

Consider this Lambda function triggered by a DynamoDB Stream event that logs the "NewImage" of the record:

medium📝 Predict Output Q4 of 15
DynamoDB - with Serverless
Consider this Lambda function triggered by a DynamoDB Stream event that logs the "NewImage" of the record:
exports.handler = async (event) => {
  event.Records.forEach(record => {
    console.log(JSON.stringify(record.dynamodb.NewImage));
  });
};
What will be logged if an item with {"userId": "789", "active": true} is inserted?
AAn error because NewImage is undefined on insert
B{"userId":"789","active":true}
Cnull
D{"userId":{"S":"789"},"active":{"BOOL":true}}
Step-by-Step Solution
Solution:
  1. Step 1: Understand DynamoDB Stream record format

    NewImage contains the new item in DynamoDB's attribute value format (with types).
  2. Step 2: Analyze the inserted item

    The item has a string and a boolean attribute, so NewImage will show {"S":"789"} and {"BOOL":true} respectively.
  3. Final Answer:

    {"userId":{"S":"789"},"active":{"BOOL":true}} -> Option D
  4. Quick Check:

    NewImage uses DynamoDB attribute types [OK]
Quick Trick: NewImage logs DynamoDB typed attributes [OK]
Common Mistakes:
MISTAKES
  • Expecting plain JSON without DynamoDB types
  • Assuming NewImage is null on insert
  • Confusing OldImage with NewImage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes