Given a DynamoDB stream event with the following record snippet, what will the Lambda function log for the NewImage attribute?
{
"Records": [
{
"eventID": "1",
"eventName": "INSERT",
"dynamodb": {
"NewImage": {
"UserId": {"S": "123"},
"Score": {"N": "42"}
}
}
}
]
}Assume the Lambda code logs event.Records[0].dynamodb.NewImage.UserId.S and event.Records[0].dynamodb.NewImage.Score.N.
Remember DynamoDB stream records store attribute values as objects with type keys like S for string and N for number.
The NewImage attribute contains the new item data with each attribute wrapped in an object indicating its type. Accessing UserId.S gives the string value "123" and Score.N gives the string "42".
Which of the following DynamoDB stream event types can trigger a Lambda function?
Think about the standard DynamoDB stream event names.
DynamoDB streams emit events named INSERT (new item added), MODIFY (item updated), and REMOVE (item deleted). These trigger Lambda functions.
Which option contains a syntax error in this Lambda function snippet that processes DynamoDB stream events?
exports.handler = async (event) => {
for (const record of event.Records) {
console.log('Event ID:', record.eventID);
console.log('Event Name:', record.eventName);
console.log('New Image:', record.dynamodb.NewImage);
}
}Check the arrow function syntax and console.log usage.
The arrow function syntax is correct with one parameter without parentheses. Semicolons are optional in JavaScript. The code is syntactically valid.
You want to optimize your Lambda function triggered by DynamoDB Streams to process records efficiently without timing out. Which approach is best?
Consider balancing throughput and Lambda execution time.
Setting a moderate batch size and processing records asynchronously with error handling balances performance and reliability, avoiding timeouts and partial failures.
Consider this Lambda function snippet triggered by DynamoDB Streams:
exports.handler = async (event) => {
event.Records.forEach(async (record) => {
await processRecord(record);
});
};Why might some records not be processed before the Lambda finishes?
Think about how async functions behave inside forEach loops.
Array.forEach does not wait for async callbacks to finish, so the Lambda may exit before all processRecord promises resolve. Using a for...of loop with await or Promise.all fixes this.