Skip to content

How batchWriteItem cost is determined?

0

Here are things that the AWS DynamoDB document says: "When you select on-demand capacity mode for your DynamoDB table, you pay only for the reads and writes your application performs. You can make API calls as needed without managing throughput capacity on the table. DynamoDB handles the management of hardware resources to accommodate your workload with consistent, low-latency performance. DynamoDB charges one write request unit for each write (up to 1 KB) and two write request units for transactional writes. For reads, DynamoDB charges one read request unit for each strongly consistent read (up to 4 KB), two read request units for each transactional read, and one-half read request unit for each eventually consistent read. The prices for read and write requests depend on your table class."

Read request unit: API calls to read data from your table are billed in read request units. DynamoDB read requests can be either strongly consistent, eventually consistent, or transactional. A strongly consistent read request of up to 4 KB requires one read request unit. For items larger than 4 KB, additional read request units are required. For items up to 4 KB in size, an eventually consistent read request requires one-half read request unit, and a transactional read request requires two read request units. For example, a strongly consistent read request of an 8 KB item requires two read request units, an eventually consistent read of an 8 KB item requires one read request unit, and a transactional read of an 8 KB item requires four read request units. See Read Consistency for more details.

Write request unit: API calls to write data to your table are billed in write request units. A standard write request unit can write an item up to 1 KB. For items larger than 1 KB, additional write request units are required. A transactional write requires two write request units. For example, a write request of a 1 KB item requires one write request unit, a write request of a 3 KB item requires three write request units, and a transactional write request of a 3 KB item requires six write request units.

-- Here is my question: If I have 3 100-byte-sizing items and use the batchWriteItem API to write them once, is this API call charged by 1 WCU or 3 WCUs?

asked 2 years ago765 views

1 Answer
0
Accepted Answer

When using the BatchWriteItem API to write 3 items of 100 bytes each, you would be charged for 3 Write Capacity Units (WCUs), not 1 WCU.

The BatchWriteItem operation processes each item in the batch as an individual PutItem or DeleteItem request. DynamoDB calculates the consumed capacity for each item separately, even though they are sent in a single API call.

For write operations, DynamoDB charges one write unit for each item up to 1 KB in size. Even though each of your items is only 100 bytes, which is less than 1 KB, DynamoDB rounds up the size of each item to the next 1 KB boundary for capacity calculation purposes.

So, in your case:

  • Item 1 (100 bytes): 1 WCU
  • Item 2 (100 bytes): 1 WCU
  • Item 3 (100 bytes): 1 WCU

Total: 3 WCUs

It's important to note that while BatchWriteItem can improve efficiency by allowing you to write multiple items in a single API call, it doesn't reduce the number of write capacity units consumed. Each item still consumes capacity as if it were written individually.

This pricing model applies regardless of whether you're using provisioned capacity or on-demand capacity mode. In on-demand mode, you would be billed for 3 write request units for this operation.
Sources
DynamoDB read and write operations - Amazon DynamoDB
BatchWriteItem - Amazon DynamoDB

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.