0
0
DynamoDBquery~20 mins

UpdateItem basics in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DynamoDB UpdateItem 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 UpdateItem operation?

Given a DynamoDB table Users with a primary key UserID and an attribute Age, what will be the new value of Age after running this UpdateItem?

{
  TableName: "Users",
  Key: { "UserID": { "S": "user123" } },
  UpdateExpression: "SET Age = Age + :inc",
  ExpressionAttributeValues: { ":inc": { "N": "5" } },
  ReturnValues: "UPDATED_NEW"
}

Assume the current Age is 30.

DynamoDB
TableName: "Users"
Key: { "UserID": { "S": "user123" } }
UpdateExpression: "SET Age = Age + :inc"
ExpressionAttributeValues: { ":inc": { "N": "5" } }
ReturnValues: "UPDATED_NEW"
A{"Age": 35}
B{"Age": 5}
C{"Age": 30}
DSyntaxError
Attempts:
2 left
💡 Hint

Think about how the SET expression updates the existing value.

📝 Syntax
intermediate
1:30remaining
Which UpdateExpression syntax is valid to set a new attribute?

Which of the following UpdateExpression syntaxes correctly adds a new attribute Status with value Active?

ASET Status = :status
BADD Status = 'Active'
CSET Status = Active
DUPDATE Status = 'Active'
Attempts:
2 left
💡 Hint

Remember to use ExpressionAttributeValues for values in UpdateExpression.

query_result
advanced
2:00remaining
What happens if you try to increment a non-existing numeric attribute?

Consider this UpdateItem request on a DynamoDB table where the attribute Score does not exist yet for the item:

{
  TableName: "Games",
  Key: { "GameID": { "S": "game789" } },
  UpdateExpression: "SET Score = Score + :val",
  ExpressionAttributeValues: { ":val": { "N": "10" } },
  ReturnValues: "UPDATED_NEW"
}

What will be the result?

AScore attribute is created with value 10
BUpdate fails with a ConditionalCheckFailedException
CScore attribute remains undefined
DUpdate fails with a ValidationException
Attempts:
2 left
💡 Hint

Think about how DynamoDB handles arithmetic on missing attributes.

🔧 Debug
advanced
2:00remaining
Why does this UpdateItem request fail with a syntax error?

Examine this UpdateItem snippet:

{
  TableName: "Employees",
  Key: { "EmpID": { "S": "e123" } },
  UpdateExpression: "SET #n = :name",
  ExpressionAttributeNames: { "#n": "Name" },
  ExpressionAttributeValues: { ":name": "John" },
  ReturnValues: "UPDATED_NEW"
}

Why does it fail?

AExpressionAttributeNames key #n is invalid
BExpressionAttributeValues value for :name is missing type wrapper
CUpdateExpression syntax is incorrect
DReturnValues value is invalid
Attempts:
2 left
💡 Hint

Check the format of ExpressionAttributeValues.

🧠 Conceptual
expert
2:30remaining
Which UpdateItem option ensures atomic increment of a numeric attribute?

You want to safely increment a numeric attribute Count in a DynamoDB item without overwriting concurrent updates. Which UpdateItem approach guarantees atomic increment?

ARead the item, increment Count in code, then write back with PutItem
BUse UpdateExpression: "SET Count = Count + :inc" with ExpressionAttributeValues {":inc": {"N": "1"}}
CUse UpdateExpression: "ADD Count :inc" with ExpressionAttributeValues {":inc": {"N": "1"}}
DUse ConditionExpression to check Count before updating with SET
Attempts:
2 left
💡 Hint

Consider DynamoDB's atomic update operators.