Bird
Raised Fist0
DynamoDBquery~20 mins

Return values on write in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Return Values Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What does ReturnValues: "ALL_OLD" return on a PutItem?
You perform a PutItem operation with ReturnValues set to "ALL_OLD". What will the response contain if the item did not exist before?
DynamoDB
PutItem({ TableName: "Users", Item: { UserId: "123", Name: "Alice" }, ReturnValues: "ALL_OLD" })
AThe primary key attributes only
BAn empty object because no previous item existed
CAn error because <code>ALL_OLD</code> is invalid for <code>PutItem</code>
DThe newly inserted item attributes
Attempts:
2 left
💡 Hint
Think about what ALL_OLD means when no item was replaced.
query_result
intermediate
2:00remaining
What does ReturnValues: "UPDATED_NEW" return on an UpdateItem?
You run an UpdateItem with ReturnValues set to "UPDATED_NEW". What will the response contain?
DynamoDB
UpdateItem({ TableName: "Products", Key: { Id: "p1" }, UpdateExpression: "SET Price = :p", ExpressionAttributeValues: { ":p": 20 }, ReturnValues: "UPDATED_NEW" })
AAll attributes of the item after the update
BAll attributes of the item before the update
COnly the attributes that were updated with their new values
DNo attributes, just a success status
Attempts:
2 left
💡 Hint
Focus on what UPDATED_NEW means in the context of updated attributes.
📝 Syntax
advanced
2:00remaining
Which ReturnValues option is invalid for DeleteItem?
Select the ReturnValues option that will cause a syntax or runtime error when used with DeleteItem.
DynamoDB
DeleteItem({ TableName: "Orders", Key: { OrderId: "o123" }, ReturnValues: ? })
A"ALL_OLD"
B"ALL_NEW"
C"NONE"
D"UPDATED_NEW"
Attempts:
2 left
💡 Hint
Consider which return values make sense for a delete operation.
🧠 Conceptual
advanced
2:00remaining
Why use ReturnValues: "ALL_NEW" in UpdateItem?
What is the main reason to set ReturnValues to "ALL_NEW" when updating an item?
ATo get the entire item as it looks after the update
BTo get only the attributes that were updated
CTo get the item as it was before the update
DTo prevent the update from happening if the item exists
Attempts:
2 left
💡 Hint
Think about when you want to see the full updated item.
🔧 Debug
expert
3:00remaining
Why does this UpdateItem with ReturnValues: "ALL_OLD" return empty?
You run this UpdateItem on a non-existing item with ReturnValues set to "ALL_OLD". Why is the returned attribute map empty?
DynamoDB
UpdateItem({ TableName: "Inventory", Key: { ItemId: "i999" }, UpdateExpression: "SET Stock = :s", ExpressionAttributeValues: { ":s": 10 }, ReturnValues: "ALL_OLD" })
ABecause the item did not exist before, so no old attributes to return
BBecause <code>ALL_OLD</code> only returns updated attributes, and none were updated
CBecause <code>ReturnValues</code> is ignored on <code>UpdateItem</code>
DBecause the update failed silently without error
Attempts:
2 left
💡 Hint
Consider what ALL_OLD means when the item is new.

Practice

(1/5)
1. What does the ReturnValues parameter do in a DynamoDB write operation?
easy
A. It specifies what data should be returned after the write operation.
B. It controls the write capacity units consumed by the operation.
C. It sets the timeout duration for the write request.
D. It defines the table where data will be written.

Solution

  1. Step 1: Understand the role of ReturnValues

    The ReturnValues parameter tells DynamoDB what data to send back after a write, such as old or new item attributes.
  2. Step 2: Differentiate from other parameters

    ReturnValues does not affect capacity, timeout, or table selection; it only controls returned data.
  3. Final Answer:

    It specifies what data should be returned after the write operation. -> Option A
  4. Quick Check:

    ReturnValues controls returned data [OK]
Hint: ReturnValues returns data after write, not capacity or timeout [OK]
Common Mistakes:
  • Confusing ReturnValues with capacity settings
  • Thinking it sets request timeout
  • Assuming it selects the table
2. Which of the following is the correct syntax to request the old item attributes after an update in DynamoDB using ReturnValues?
easy
A. "UPDATED_NEW"
B. "NONE"
C. "ALL_NEW"
D. "ALL_OLD"

Solution

  1. Step 1: Recall ReturnValues options

    ReturnValues can be NONE, ALL_OLD, UPDATED_OLD, ALL_NEW, UPDATED_NEW.
  2. Step 2: Identify option for old attributes after update

    "ALL_OLD" returns the entire item as it was before the update.
  3. Final Answer:

    "ALL_OLD" -> Option D
  4. Quick Check:

    Old attributes = ALL_OLD [OK]
Hint: Old data after update is ALL_OLD [OK]
Common Mistakes:
  • Using ALL_NEW to get old data
  • Confusing UPDATED_NEW with old data
  • Setting NONE expecting data back
3. Given this DynamoDB update command snippet:
{
  TableName: "Users",
  Key: { "UserId": "123" },
  UpdateExpression: "SET Age = :newAge",
  ExpressionAttributeValues: { ":newAge": 30 },
  ReturnValues: "UPDATED_NEW"
}

What will the response contain?
medium
A. The entire item before the update.
B. Only the new Age attribute after the update.
C. No attributes, just success confirmation.
D. The entire item after the update.

Solution

  1. Step 1: Understand ReturnValues "UPDATED_NEW" meaning

    This option returns only the attributes that were updated with their new values.
  2. Step 2: Apply to given update

    The update changes Age to 30, so response includes only Age with value 30.
  3. Final Answer:

    Only the new Age attribute after the update. -> Option B
  4. Quick Check:

    UPDATED_NEW returns updated attributes [OK]
Hint: UPDATED_NEW returns only changed attributes with new values [OK]
Common Mistakes:
  • Expecting full item back with UPDATED_NEW
  • Confusing UPDATED_NEW with ALL_NEW
  • Assuming no data returned with UPDATED_NEW
4. You wrote this DynamoDB PutItem request:
{
  TableName: "Products",
  Item: { "Id": "001", "Name": "Pen" },
  ReturnValues: "UPDATED_OLD"
}

But you get an error. What is wrong?
medium
A. ReturnValues must be set to "ALL_NEW" for PutItem.
B. The Item attribute is missing required keys.
C. "UPDATED_OLD" is invalid for PutItem operations.
D. TableName is incorrect.

Solution

  1. Step 1: Check ReturnValues compatibility with PutItem

    PutItem supports only NONE or ALL_OLD for ReturnValues; UPDATED_OLD is invalid.
  2. Step 2: Confirm other parameters

    Item and TableName are correct; error is due to invalid ReturnValues.
  3. Final Answer:

    "UPDATED_OLD" is invalid for PutItem operations. -> Option C
  4. Quick Check:

    PutItem supports NONE or ALL_OLD only [OK]
Hint: PutItem allows NONE or ALL_OLD only for ReturnValues [OK]
Common Mistakes:
  • Using UPDATED_OLD with PutItem
  • Assuming ALL_NEW required for PutItem
  • Mistaking missing keys as cause
5. You want to update a user's email in DynamoDB and get back the entire updated item in one request. Which ReturnValues option should you use in your UpdateItem call?
hard
A. "ALL_NEW"
B. "UPDATED_OLD"
C. "NONE"
D. "ALL_OLD"

Solution

  1. Step 1: Understand the goal

    You want the full updated item returned after the update.
  2. Step 2: Match ReturnValues option

    "ALL_NEW" returns the entire item as it looks after the update.
  3. Final Answer:

    "ALL_NEW" -> Option A
  4. Quick Check:

    Full updated item = ALL_NEW [OK]
Hint: Use ALL_NEW to get full updated item after update [OK]
Common Mistakes:
  • Choosing UPDATED_OLD which returns old updated attributes
  • Using NONE expecting data back
  • Selecting ALL_OLD which returns old full item