Bird
0
0

Given the following code snippet, what will be logged if the item exists in the DynamoDB table?

medium📝 Predict Output Q13 of 15
DynamoDB - with AWS SDK
Given the following code snippet, what will be logged if the item exists in the DynamoDB table?
import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb';
const client = new DynamoDBClient({ region: 'us-east-1' });

async function getItem() {
  const command = new GetItemCommand({
    TableName: 'Users',
    Key: { 'UserId': { S: '123' } }
  });
  const response = await client.send(command);
  console.log(response.Item);
}
getItem();
AUndefined because no item exists
BAn empty object {}
CAn error is thrown due to missing parameters
DThe item object with attributes if found
Step-by-Step Solution
Solution:
  1. Step 1: Understand GetItemCommand behavior

    GetItemCommand returns an object with an Item property if the item exists.
  2. Step 2: Analyze console.log output

    Logging response.Item will show the item's attributes as an object if found.
  3. Final Answer:

    The item object with attributes if found -> Option D
  4. Quick Check:

    response.Item = item object [OK]
Quick Trick: GetItemCommand returns Item if found, else undefined [OK]
Common Mistakes:
MISTAKES
  • Expecting an error when item is missing
  • Assuming response itself is the item
  • Confusing empty object with undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes