DEV Community

Abhishek Gupta for AWS

Posted on • Originally published at community.aws

[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

Top comments (0)