DEV Community

Abhishek Gupta for AWS

Posted on • Originally published at community.aws

3 1

[20 Days of DynamoDB] Day 7 - DeleteItem API

Posted: 16/Jan/2024

The DynamoDB DeleteItem API does what it says - delete an item. But it can also:

  • Return the content of the old item (at no additional cost)
  • Return the consumed Write Capacity Units (WCU)
  • Return the item attributes for an operation that failed a condition check (again, no additional cost)
  • Retrieve statistics about item collections, if any, that were affected during the operation

Here is an example:

    resp, err := client.DeleteItem(context.Background(), &dynamodb.DeleteItemInput{
        TableName: aws.String(tableName),
        Key: map[string]types.AttributeValue{
            "email": &types.AttributeValueMemberS{Value: email},
        },

        ReturnValues:                        types.ReturnValueAllOld,
        ReturnConsumedCapacity:              types.ReturnConsumedCapacityTotal,
        ReturnValuesOnConditionCheckFailure: types.ReturnValuesOnConditionCheckFailureAllOld,
        ReturnItemCollectionMetrics:         types.ReturnItemCollectionMetricsSize,
    })
Enter fullscreen mode Exit fullscreen mode

Recommended reading - DeleteItem API doc

Billboard image

Monitoring as code

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 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