Bird
0
0

Why does the following Lambda function fail to update an item in DynamoDB?

medium📝 Debug Q7 of 15
DynamoDB - with Serverless
Why does the following Lambda function fail to update an item in DynamoDB? ```javascript const AWS = require('aws-sdk'); const docClient = new AWS.DynamoDB.DocumentClient(); exports.handler = async (event) => { const params = { TableName: 'Users', Key: { userId: event.userId }, UpdateExpression: 'set email = :email', ExpressionAttributeValues: { ':email': event.email } }; await docClient.update(params).promise(); return { statusCode: 200 }; }; ```
AUpdateExpression syntax is incorrect; should use 'SET' in uppercase
BMissing ReturnValues parameter to confirm update success
CExpressionAttributeValues keys must not start with a colon
DKey attribute 'userId' must be a string literal, not event variable
Step-by-Step Solution
Solution:
  1. Step 1: Check UpdateExpression syntax

    UpdateExpression keywords are case-sensitive and must be uppercase 'SET'.
  2. Step 2: Identify the error

    The code uses 'set' lowercase, which causes the update to fail.
  3. Final Answer:

    UpdateExpression syntax is incorrect; should use 'SET' in uppercase -> Option A
  4. Quick Check:

    Verify DynamoDB UpdateExpression syntax [OK]
Quick Trick: Use uppercase keywords in UpdateExpression [OK]
Common Mistakes:
MISTAKES
  • Using lowercase keywords in UpdateExpression
  • Misunderstanding ExpressionAttributeValues syntax
  • Assuming ReturnValues is mandatory for update

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes