Bird
0
0

What is wrong with the following code snippet that tries to put an item into DynamoDB?

medium📝 Debug Q14 of 15
DynamoDB - with AWS SDK
What is wrong with the following code snippet that tries to put an item into DynamoDB?
import { DynamoDBClient, PutItemCommand } from '@aws-sdk/client-dynamodb';
const client = new DynamoDBClient({ region: 'us-east-1' });

async function putItem() {
  const command = new PutItemCommand({
    TableName: 'Users',
    Item: { UserId: '123', Name: 'Alice' }
  });
  await client.send(command);
}
putItem();
ATableName should be lowercase
BItem attributes must be wrapped with DynamoDB data types like { S: 'value' }
CPutItemCommand does not exist in AWS SDK
DMissing await before client.send
Step-by-Step Solution
Solution:
  1. Step 1: Check Item attribute format

    DynamoDB expects attribute values wrapped in type descriptors like { S: 'string' }.
  2. Step 2: Identify the error cause

    Passing plain strings without type wrappers causes validation errors.
  3. Final Answer:

    Item attributes must be wrapped with DynamoDB data types like { S: 'value' } -> Option B
  4. Quick Check:

    Attribute values need type wrappers [OK]
Quick Trick: Always wrap attribute values with DynamoDB types (S, N, etc.) [OK]
Common Mistakes:
MISTAKES
  • Passing plain strings instead of typed attributes
  • Assuming table names are case-insensitive
  • Forgetting to await async calls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes