Does AWS DynamoDB consume throuput or charges for a Put Item (write) operation that failed due to a conditional expression?

Viewed 450

I wasn't able to find a straightforward answer for this.

Consider a DynamoDB Put Item request with a condition expression.

Say the condition fails and DynamoDB returns an error. In other words: the Put Item request does not succeed and nothing is effectively written.

Does this request still consume write throuput capacity (or is charged, if the table is in on-demand mode)?

1 Answers

If a ConditionExpression evaluates to false during a conditional write, DynamoDB still consumes write capacity from the table:

  • If the item does not currently exist in the table, DynamoDB consumes one write capacity unit.

  • If the item does exist, the number of write capacity units consumed depends on the size of the item. For example, a failed conditional write of a 1 KB item would consume one write capacity unit. If the item were twice that size, the failed conditional write would consume two write capacity units.

A failed conditional write returns a ConditionalCheckFailedException. When this occurs, you don't receive any information in the response about the write capacity that was consumed. However, you can view the ConsumedWriteCapacityUnits metric for the table in Amazon CloudWatch.

This and more information can be found in the DynamoDB documentation article Working with Items and Attributes.

Related