Bird
0
0

Given this Lambda function snippet, what will be the output if the item with id '123' exists in the DynamoDB table?

medium📝 query result Q13 of 15
DynamoDB - with Serverless
Given this Lambda function snippet, what will be the output if the item with id '123' exists in the DynamoDB table?
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient();

exports.handler = async (event) => {
  const params = {
    TableName: 'Users',
    Key: { id: '123' }
  };
  const data = await docClient.get(params).promise();
  return data.Item;
};
AAn error because 'get' method is incorrect
BA list of all items in the Users table
CAn empty object {}
DThe item object with id '123' from the Users table
Step-by-Step Solution
Solution:
  1. Step 1: Understand docClient.get usage

    The get method retrieves a single item by key from the specified table.
  2. Step 2: Analyze the return value

    If the item with id '123' exists, data.Item will contain that item object.
  3. Final Answer:

    The item object with id '123' from the Users table -> Option D
  4. Quick Check:

    docClient.get returns item if found [OK]
Quick Trick: docClient.get returns single item by key [OK]
Common Mistakes:
MISTAKES
  • Expecting a list instead of single item
  • Thinking get method is invalid
  • Assuming empty object if item exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes