0
0
DynamoDBquery~20 mins

BatchWriteItem in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
BatchWriteItem Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the result of this BatchWriteItem operation?

Consider a DynamoDB table named Users with primary key UserId. You run the following BatchWriteItem request to insert two new users:

{
  "RequestItems": {
    "Users": [
      {"PutRequest": {"Item": {"UserId": {"S": "u1"}, "Name": {"S": "Alice"}}}},
      {"PutRequest": {"Item": {"UserId": {"S": "u2"}, "Name": {"S": "Bob"}}}}
    ]
  }
}

What will the response contain if both writes succeed?

A{"UnprocessedItems": {}}
B{"UnprocessedItems": {"Users": [{"PutRequest": {"Item": {"UserId": {"S": "u1"}, "Name": {"S": "Alice"}}}}]}}
C{"Error": "ProvisionedThroughputExceededException"}
D{"ConsumedCapacity": [{"TableName": "Users", "CapacityUnits": 2}]}
Attempts:
2 left
💡 Hint

If all writes succeed, DynamoDB returns an empty UnprocessedItems map.

🧠 Conceptual
intermediate
2:00remaining
Which limitation applies to BatchWriteItem requests?

When using BatchWriteItem in DynamoDB, which of the following is a true limitation?

AYou can write unlimited items as long as the total size is under 100 MB.
BYou can write up to 25 items or 16 MB of data per request, whichever limit is hit first.
CBatchWriteItem supports conditional writes on items.
DYou can only write items to one table per BatchWriteItem request.
Attempts:
2 left
💡 Hint

Check the official AWS DynamoDB limits for batch writes.

📝 Syntax
advanced
2:00remaining
Which BatchWriteItem request syntax is valid?

Identify the valid JSON syntax for a BatchWriteItem request that deletes an item with UserId 'u3' from the Users table.

A
{
  "RequestItems": {
    "Users": {
      "DeleteRequest": {"Key": {"UserId": {"S": "u3"}}}
    }
  }
}
B
{
  "RequestItems": {
    "Users": [
      {"Delete": {"Key": {"UserId": "u3"}}}
    ]
  }
}
C
{
  "RequestItems": {
    "Users": [
      {"DeleteRequest": {"Key": {"UserId": {"S": "u3"}}}}
    ]
  }
}
D
{
  "RequestItems": [
    {"Users": {"DeleteRequest": {"Key": {"UserId": {"S": "u3"}}}}}
  ]
}
Attempts:
2 left
💡 Hint

Remember the structure: RequestItems maps table names to lists of write requests.

optimization
advanced
2:00remaining
How to handle unprocessed items efficiently after BatchWriteItem?

After calling BatchWriteItem, some items are returned in UnprocessedItems. What is the best practice to handle these unprocessed items?

ARetry the unprocessed items with exponential backoff until all are processed.
BDelete the unprocessed items from your application to avoid duplicates.
CSplit unprocessed items into single-item requests and send them immediately without delay.
DIgnore unprocessed items as they will be processed automatically by DynamoDB.
Attempts:
2 left
💡 Hint

Think about how to avoid throttling and ensure all writes succeed.

🔧 Debug
expert
2:00remaining
Why does this BatchWriteItem request fail with ValidationException?

You run this BatchWriteItem request to put two items into the Products table:

{
  "RequestItems": {
    "Products": [
      {"PutRequest": {"Item": {"ProductId": {"S": "p1"}, "Price": {"N": "20"}}}},
      {"PutRequest": {"Item": {"ProductId": {"S": "p2"}, "Price": 15}}}
    ]
  }
}

Why does this request cause a ValidationException?

AThe JSON syntax is invalid due to a missing comma after the second PutRequest.
BThe ProductId attribute must be a number, not a string.
CBatchWriteItem does not support multiple PutRequests in one call.
DThe second item's Price attribute is missing the DynamoDB data type wrapper.
Attempts:
2 left
💡 Hint

Check the attribute value formats for DynamoDB items.