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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay