DEV Community

Abhishek Gupta for AWS

Posted on • Originally published at community.aws

1 2 2 1 1

[20 Days of DynamoDB] Day 3 - UpdateItem add-on benefits

Posted: 10/Jan/2024

The DynamoDB UpdateItem operation is quite flexible. In addition to using many types of operations, you can:

  • Use multiple update expressions in a single statement
  • Get the item attributes as they appear before or after they are successfully updated
  • Understand which item attributes failed the condition check (no additional cost)
  • Retrieve the consumed Write Capacity Units (WCU)

Here is an example (using AWS Go SDK v2):

    resp, err = client.UpdateItem(context.Background(), &dynamodb.UpdateItemInput{
        TableName: aws.String(tableName),
        Key: map[string]types.AttributeValue{
            "email": &types.AttributeValueMemberS{Value: email},
        },
        UpdateExpression: aws.String("SET last_name = :ln REMOVE category"),
        ExpressionAttributeValues: map[string]types.AttributeValue{
            ":ln": &types.AttributeValueMemberS{
                Value: lastName,
            },
        },
        ReturnValues:                        types.ReturnValueAllOld,
        ReturnValuesOnConditionCheckFailure: types.ReturnValuesOnConditionCheckFailureAllOld,
        ReturnConsumedCapacity:              types.ReturnConsumedCapacityTotal,
    }
Enter fullscreen mode Exit fullscreen mode

Recommended reading:

Billboard image

The fastest way to detect downtimes

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitoring.

Get started now

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay