My Amazon DynamoDB PutItem operation is successful, but GetItem doesn't return the latest data
Last updated: 2020-07-09
When I write a record to a table, PutItem returns a successful HTTP 200 response. However, when I try to fetch the item in a read request, Amazon DynamoDB doesn't return the updated record.
This usually happens when you use an eventually consistent read to access an item immediately after writing it to a table. GetItem provides an eventually consistent read by default. If you repeat your read request after a short time, the response should return the updated data.
If you want to retrieve the latest data as soon as the write request is successful, set the ConsistentRead parameter to true. This enables strongly consistent reads. Note the following about strongly consistent reads:
- Strongly consistent reads might have higher latency.
- Strongly consistent reads aren't supported on global secondary indexes.
- Strongly consistent reads require twice as much throughput as eventually consistent reads. This means that strongly consistent reads cost twice as much as eventually consistent reads. For more information, see Pricing for provisioned capacity or Pricing for on-demand capacity.
For an example request that uses strongly consistent reads, see Retrieve item attributes.