Forecast DynamoDB write costs for an AI usage ledger by measuring the write request units (WRUs) consumed by the table and each global secondary index (GSI). Use ReturnConsumedCapacity=INDEXES on representative successful writes and estimate billed units for conditional rejections from their counts and item sizes. If a smaller projection brings one index entry from two WRUs to one, two million successful monthly inserts save two million WRUs. Check which fields the reports need before changing the projection.
Last reviewed: 2026-11-22 (UTC, 2026-11-23 in Asia/Shanghai).
Count writes by operation and index
For a single-Region on-demand table, each successful nontransactional write costs one WRU per 1 KB of item size, rounded up per item. Inserting a 1.5 KB item consumes two WRUs on the base table. Adding a 1.5 KB entry to one GSI consumes two more. Grouping inserts into a batch still rounds each item individually. For a replacement or an update, use the larger of the before and after item sizes to estimate the base table write. See DynamoDB read and write operations .
Count how many times the application writes each attempt. A writer that inserts a pending event and updates it with final token counts has two base table writes to measure. An update to a projected token count needs one index write if the index key stays the same. If status is part of an index key, a status change deletes the old index entry and inserts a new one. A write confined to attributes outside the projection and index keys takes zero units on that index. See Using Global Secondary Indexes in DynamoDB .
For each operation, use the distribution of observed units. For instance, if 90 in 100 events cost one unit on the table and 10 cost two, the average is 1.1 units per insert. Measure the table and indexes for the same set of writes, including larger usage events with more billing fields. Treat the durable accounting path as a requirement when reducing what gets indexed. See Keep AI API cost records independent of trace sampling .
Compare two projections with the same usage event
Use two disposable on-demand tables in the same account and Region. Give each a string partition key named attempt_id and one GSI named by_workload with a string partition key named workload_day. Use ALL on the baseline index. Use INCLUDE on the candidate index and select input_tokens, output_tokens, and usage_state as its non-key attributes. DynamoDB includes the base and index key attributes in the projection. Wait for both tables and indexes to be active before comparing writes. See the index projection options
.
Run the command once per table with the same synthetic event. Set AWS_PROFILE to an AWS CLI v2 profile for your authorized sandbox, AWS_REGION to its Region, LEDGER_FIXTURE_TABLE to the disposable table name, and FIXTURE_ATTEMPT_ID to a new string such as fixture-01. The command uses jq to build the item and a condition to protect an existing fixture row from replacement. Each successful run performs a DynamoDB write against the sandbox.
(
set -eu
fixture_item=$(jq -cn --arg attempt_id "${FIXTURE_ATTEMPT_ID:?Set a fresh fixture ID}" '
{
attempt_id: {S: $attempt_id},
workload_day: {S: "fixture-workload#2026-11-23"},
input_tokens: {N: "560"},
output_tokens: {N: "120"},
usage_state: {S: "settled"},
evidence_note: {S: ("x" * 1300)}
}
')
aws dynamodb put-item \
--profile "${AWS_PROFILE:?Set the sandbox AWS profile}" \
--region "${AWS_REGION:?Set the sandbox Region}" \
--table-name "${LEDGER_FIXTURE_TABLE:?Set the disposable table name}" \
--item "$fixture_item" \
--condition-expression 'attribute_not_exists(attempt_id)' \
--return-consumed-capacity INDEXES \
--query 'ConsumedCapacity.{total:CapacityUnits,table:Table.CapacityUnits,index:GlobalSecondaryIndexes.by_workload.CapacityUnits}' \
--output json --no-cli-pager
)
The fixture puts both base items in the two-unit tier. The expected outputs for total, table, and index are 4, 2, and 2 with ALL, and 3, 2, and 1 with INCLUDE. These are expected results from the documented size rules. Save the measured response from each sandbox write with its projection and fixture ID. If index is missing for this fixture, verify the index name, status, and the presence of workload_day before using the result. The aggregate total already includes the index charge. See the AWS CLI put-item reference
.
After a successful insert, run the same command once more against the same sandbox table with the same fixture ID. Expect ConditionalCheckFailedException because attribute_not_exists(attempt_id) evaluates to false. DynamoDB charges the base table for the failed condition using the existing item’s size. For this fixture, that is an estimated two WRUs. The exception response omits consumed capacity even with INDEXES, so record the rejection alongside the successful response. See Working with items and attributes in DynamoDB
.
Query by_workload on both tables for workload_day equal to fixture-workload#2026-11-23. Look for fixture-01 with 560 input tokens, 120 output tokens, and a settled state. GSI reads are eventually consistent. Allow a bounded wait and investigate if the entry never appears. The candidate projection leaves evidence_note available on the base item. If a report uses that field, measure the cost and latency of fetching it from the table by key. See GSI queries and attribute projections
.
Turn per-write measurements into a monthly forecast
Multiply each successful operation’s monthly count by its average measured units, then sum across operations. In this worked example, two million events each arrive as a single successful insert with the same unit counts as the fixture. Your application’s successful settlement updates, corrections, and repeated writes need their own counts and measurements.
| Monthly WRUs for successful inserts | ALL projection | INCLUDE projection |
|---|---|---|
| Base table | 4,000,000 | 4,000,000 |
by_workload index | 4,000,000 | 2,000,000 |
| Total | 8,000,000 | 6,000,000 |
The fixture forecast is a 25% reduction in WRUs for successful inserts. When the real entries for both projections fall in the same size tier, they consume the same number of units per insert. If a projected field changes often in production, measure that update on both configurations as well. Dropping the field from the projection can avoid an index write when just that field changes.
Count ConditionalCheckFailedException outcomes at the DynamoDB call boundary by table, operation, and UTC window. Group the rejections by estimated size of the stored item at the time of the failure. For each size group, round the item size up in 1 KB steps and multiply the resulting WRUs by the rejection count. Use one WRU for a condition that fails when the item is absent. If item sizes are uncertain, sample representative stored items and record the size assumptions in the forecast. See capacity units consumed by conditional writes
.
If each projection sees 100,000 rejected duplicates against existing two-WRU items, add 200,000 base-table WRUs to each successful-write subtotal. That brings the combined estimate to 8.2 million WRUs with ALL and 6.2 million with INCLUDE, about a 24.4% reduction. Multiply each combined total in millions by the applicable price per million WRUs.
Reconcile the combined estimate, including conditional rejections, against billed write units in the DynamoDB usage export for the same UTC window, Region, and table class. AWS distinguishes WriteRequestUnits for Standard tables from IA-WriteRequestUnits for Standard-IA tables, with Region prefixes where applicable. Use a resource identifier where your export includes it. Track the fraction of ledger writes covered by your measurement so a partial sample can be scaled with a known denominator. See DynamoDB billing and usage reports
.
Approve a projection change after it returns the required fields and lowers the estimated total for writes, reads, and storage at the expected workload. Estimate the one-time cost of any reads or writes your migration will issue, then reconcile the recurring write units after cutover. Keep the units visible alongside the money when converting the reduction into a budget. See Preserve sub-cent precision in AI API cost ledgers .
Sources checked
The maintained AWS references below were checked on November 22, 2026 UTC. They document the capacity model and measurement fields used in the example. The forecast uses synthetic volumes and the sandbox results are acceptance criteria.
- AWS read and write unit rounding, including replacement and batch behavior. DynamoDB read and write operations
- Index projections, asynchronous updates, and the writes generated by changes to index keys and attributes. Using Global Secondary Indexes in DynamoDB
- Conditional inserts, the
INDEXESoption, and the per-resource fields inConsumedCapacity. AWS CLI put-item - On-demand write usage types by table class and fields for reconciliation. DynamoDB billing and usage reports
- Failed conditional-write charges, existing-item sizing, and the exception response. Working with items and attributes in DynamoDB