You upload invoice.pdf once. Two Lambda invocations start. Both check DynamoDB, both see an empty result, and both ask Amazon Bedrock to summarize the same file. One summary shows up in the app. The second call is only visible in your logs.
Amazon S3 event notifications use at-least-once delivery, so duplicate notifications are a case worth testing. Here’s a small design exercise for an S3 → Lambda → Bedrock pipeline.
1. Decide what counts as the same job
With S3 versioning enabled, use the bucket, decoded object key, and version ID to identify the input. Include a pipeline revision if a new prompt or model configuration should produce a fresh summary. Read the specific object version named by the job so a late event can’t accidentally summarize a newer upload at the same key.
2. Claim the job before calling Bedrock
Use a DynamoDB conditional write with attribute_not_exists(pk) to claim the job. Store an attempt ID and a lease deadline. If a second worker sees an active lease, defer the retry. If it sees a completed job, reuse its result. For an expired lease, use a conditional update so only one worker can take over.
When the worker finishes, conditionally record the result using the attempt ID. That prevents an older worker from replacing a newer worker’s result after its lease has expired. If summaries live in S3, give each attempt its own output key and publish only the winning pointer in DynamoDB.
3. Pick what happens when the response goes missing
Imagine Bedrock finishes the inference, but Lambda times out before saving the result. The next worker can’t tell from the job record whether inference ran. Retrying may pay for a second call. Holding the job for review may leave the user waiting.
For a low-cost summary, I’d allow a bounded retry after the lease expires. For an expensive batch, I’d route ambiguous outcomes for review. Either way, track model calls per completed job alongside the number of duplicate claims skipped. One visible summary can hide two paid calls.
Try three failures before shipping
- Deliver the same object event twice at the same time. Check how many workers reach Bedrock.
- Stop the first worker after it claims the job. Check that a later retry can recover it after the lease expires.
- Stop the first worker just after inference returns. Check that your chosen retry policy actually kicks in and only one result becomes visible.
Your turn. A 200-page document times out after the inference request goes out. Would you A) retry once, B) pause for review, or C) use a different policy? What would change your answer first: inference cost, customer wait time, or how often this happens?
Loading article