TrimmedDataAccessException happens when a DynamoDB Streams consumer tries to read a record that was already evicted by the 24‑hour retention window. The SDK throws this exception with HTTP 400, and GetRecords will not return data until you recreate the iterator inside the retention window.
The TrimmedDataAccessException error means that your stream consumer is asking for a record that no longer exists because DynamoDB trims records older than 24 hours. The operation ran past the oldest record in a shard, either because the shard iterator references a sequence number older than the trim point or because a record aged out between the time you created the iterator and the moment you called GetRecords. The SDK surfaces the human-readable message “The data you are trying to access has been trimmed.” to highlight that continuous consumption fell behind the retention window.
Describe the stream and inspect RetentionPeriodHours plus the shard iterator you are using:
https://docs.aws.amazon.com/cli/latest/reference/dynamodbstreams/describe-stream.html#examples
1. Run aws dynamodbstreams describe-stream --stream-arn <arn> to read RetentionPeriodHours. The default is 24 hours.
2. Compare the iterator type you request (AT_SEQUENCE_NUMBER, AT_TIMESTAMP, TRIM_HORIZON, LATEST) with the sequence number stored in the checkpoint.
3. If you are using AT_SEQUENCE_NUMBER or a saved checkpoint, verify the sequence number is within the last 24 hours; anything older has been trimmed and cannot be read.
When the iterator has been trimmed, lesion handler must skip ahead to a fresh position:
1. Use TRIM_HORIZON (to replay everything still in retention) or LATEST (to start from the newest data) instead of the stale shard iterator.
2. Alternatively, call GetShardIterator with AT_TIMESTAMP and a timestamp that is now minus the retention window to jump just before the oldest available record.
3. For Kinesis Client Library consumers, clear the checkpoint for the affected shard (the ~cl table) so it reinitializes using a new iterator and not an expired sequence number.
This ensures the next GetRecords request points to a record that still exists inside DynamoDB Streams’ trim horizon.
Catch TrimmedDataAccessException and treat it as a signal to reset your checkpoint instead of retrying the same iterator:
npm install @aws-sdk/client-dynamodb-streams
switch (error.name) {
case 'TrimmedDataAccessException':
// log the event, optionally notify, then reset the shard iterator
await resetCheckpointShard(/* shardId */);
continue; // or break and restart consumer loop
default:
throw error;
}
Add alerts on repeated TrimmedDataAccessException spikes and monitor GetRecords error metrics. If consumers regularly fall behind hopes beyond 24 hours, consider increasing the stream retention window (up to 7 days) or keeping the application online longer.
ImportConflictException: There was a conflict when attempting to import to the table
How to fix 'ImportConflictException: There was a conflict when attempting to import to the table' in DynamoDB
ResourceNotFoundException: Requested resource not found
How to fix "ResourceNotFoundException: Requested resource not found" in DynamoDB
GlobalTableNotFoundException: Global Table not found
How to fix "GlobalTableNotFoundException: Global Table not found" in DynamoDB
InvalidExportTimeException: The specified ExportTime is outside of the point in time recovery window
How to fix "InvalidExportTimeException: The specified ExportTime is outside of the point in time recovery window" in DynamoDB
MissingAuthenticationTokenException: Missing Authentication Token
How to fix "MissingAuthenticationTokenException: Missing Authentication Token" in DynamoDB