Bird
0
0

Identify the error in this DynamoDB Document Client code snippet:

medium📝 Debug Q14 of 15
DynamoDB - with AWS SDK
Identify the error in this DynamoDB Document Client code snippet:
const params = { TableName: "Products", Item: { id: 101, name: "Pen" } };
const command = new GetCommand(params);
const result = await docClient.send(command);
console.log(result);
AUsing GetCommand with an Item parameter instead of Key
BMissing await keyword before docClient.send
CTableName should be lowercase
DItem should be a string, not an object
Step-by-Step Solution
Solution:
  1. Step 1: Check command and parameters

    GetCommand requires a Key parameter to identify the item, not an Item parameter.
  2. Step 2: Validate other options

    Await is present, TableName is case-sensitive but correct, and Item must be an object for PutCommand, not GetCommand.
  3. Final Answer:

    Using GetCommand with an Item parameter instead of Key -> Option A
  4. Quick Check:

    GetCommand needs Key, not Item = D [OK]
Quick Trick: GetCommand uses Key, PutCommand uses Item [OK]
Common Mistakes:
MISTAKES
  • Confusing Item and Key parameters
  • Ignoring case sensitivity of TableName
  • Forgetting await keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes