Skip to content

How to avoid data loss in DynamoDB event source for Lambda

0

DynamoDB Streams keep data for 24 hours. Failed event source mapping invocations can be retained in a S3 bucket. But is there any way to configure this to guarantee that unprocessed stream data will be stored in S3? I would like a bad record to block the processing on the affected shard for indefinite (above 24 hours) time without losing data. So ideally I would like the removal of data from the DynamoDB Stream to trigger a move to the configured destinations for failed invocations.

asked 2 years ago486 views

2 Answers
2

You should use a Dead Letter Queue, which will capture metadata about failed records. Then have a Lambda function listening to the DLQ, fetch the item from the stream and push to any service you see fit, such as S3. Using this approach, you lose no data and the stream can continue to operate as normal.

If you really do need longer retention periods, then consider using Kinesis Data Streams which can allow you up to 365 days of retention.

AWS
EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Yes, but I do not want the stream to continue in order to avoid data inconsistency issues further down the line. So ideally I want to have time to deploy a code fix that resolve the failed records and that could potentially take longer than 24 hours.

  • Then you must use Kinesis Data Streams, as DynamoDB will only every provide you with a maximum of 24 hours.

1

The second link you mentioned regarding retaining failed events in S3 might not be relevant. If there is a bad record that blocks processing of the shard for 24 hours, it means that the records after the failed one may get dropped from the stream, before they even got into the Lambda service. In this case, they will not be sent to S3.

I recommend that you reduce the 24 hours for failed events to prevent this situation. In addition, it will reduce your cost, as if this is a bad record, it will cause Lambda many invocations of the lambda function, which will incur cost.

AWS
EXPERT

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.