Bird
0
0

You wrote this code snippet but get a runtime error:

medium📝 Debug Q6 of 15
DynamoDB - with AWS SDK
You wrote this code snippet but get a runtime error:
const { DynamoDBClient, GetItemCommand } = require('@aws-sdk/client-dynamodb');
const client = new DynamoDBClient();
const command = new GetItemCommand({ TableName: 'Users', Key: { id: '123' } });
const response = await client.send(command);
console.log(response.Item);

What is the likely cause?
Aawait cannot be used outside async function.
BDynamoDBClient requires region configuration.
CGetItemCommand does not exist in the SDK.
DThe Key attribute must use DynamoDB attribute value format.
Step-by-Step Solution
Solution:
  1. Step 1: Check Key format for GetItemCommand

    DynamoDB expects Key values in attribute value format, e.g., { id: { S: '123' } }.
  2. Step 2: Analyze other options

    While region config is recommended, lack of it usually throws a different error. GetItemCommand exists. Await usage depends on context but error here is about Key format.
  3. Final Answer:

    The Key attribute must use DynamoDB attribute value format. -> Option D
  4. Quick Check:

    Key format must match DynamoDB attribute values [OK]
Quick Trick: Use DynamoDB attribute value format for keys [OK]
Common Mistakes:
MISTAKES
  • Passing plain values instead of attribute objects
  • Ignoring region configuration errors
  • Misunderstanding async/await usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes