Bird
0
0

You want a Lambda function to update a user's email in DynamoDB only if the user exists. Which approach correctly ensures this conditional update?

hard🚀 Application Q15 of 15
DynamoDB - with Serverless
You want a Lambda function to update a user's email in DynamoDB only if the user exists. Which approach correctly ensures this conditional update?
AUse docClient.delete before updating
BUse docClient.put without any condition
CUse docClient.update with ConditionExpression 'attribute_exists(id)'
DUse docClient.get and then docClient.put unconditionally
Step-by-Step Solution
Solution:
  1. Step 1: Understand conditional update in DynamoDB

    To update only if an item exists, use ConditionExpression with 'attribute_exists' on the key.
  2. Step 2: Apply ConditionExpression in update method

    docClient.update supports ConditionExpression to prevent overwriting non-existing items.
  3. Step 3: Evaluate other options

    Using put without condition overwrites or creates new items; delete before update is inefficient; get then put is not atomic.
  4. Final Answer:

    Use docClient.update with ConditionExpression 'attribute_exists(id)' -> Option C
  5. Quick Check:

    Conditional update = update + attribute_exists [OK]
Quick Trick: Use ConditionExpression 'attribute_exists' for safe updates [OK]
Common Mistakes:
MISTAKES
  • Using put which overwrites without condition
  • Deleting item before update unnecessarily
  • Not using atomic conditional update

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes