Skip to content

fix: SQS Delete Batch ID's should be distinct, which MessageID is not guaranteed to be#253

Closed
flipscholtz wants to merge 1 commit into
CoorpAcademy:masterfrom
civicteam:fix/sqsDuplicateDeletionBatchIds
Closed

fix: SQS Delete Batch ID's should be distinct, which MessageID is not guaranteed to be#253
flipscholtz wants to merge 1 commit into
CoorpAcademy:masterfrom
civicteam:fix/sqsDuplicateDeletionBatchIds

Conversation

@flipscholtz

@flipscholtz flipscholtz commented Aug 25, 2023

Copy link
Copy Markdown

When deleting a batch of SQS messages, the Batch ID's have to be unique.
If not, a 'BatchEntryIdsNotDistinct' error is returned and none of the messages are deleted.

Setting this ID equal to the MessageID causes problems because multiple receipts of the same message will have the same MessageID, although it's not the same ReceiptHandle.
For e.g. a single batch may contain:
messageA#receipt1
messageA#receipt2 .
In both cases, the MessageID is messageA but in terms of batched deletion it's two different items.

According to the docs here, the ID passed to DeleteBatch is just a correlation ID, so it can be set to anything user-generated:

Note
The Id s of a batch request need to be unique within a request.

This identifier can have up to 80 characters. The following characters are accepted: alphanumeric characters, hyphens(-), and underscores (_).

So we can just set it to a random UUID to avoid duplicates.

…rwise deleting multiple receipts of the same message results in a 'BatchIDsNotDistinct' error and the whole batch's deletion fails. These batch ID's are just for correlation and can be set to a random UUID.
@flipscholtz flipscholtz force-pushed the fix/sqsDuplicateDeletionBatchIds branch from 8e56c98 to b0e588e Compare August 25, 2023 18:24
@flipscholtz flipscholtz changed the title fix: SQS Delete Batch ID's should not be equal to the MessageID fix: SQS Delete Batch ID's should be distinct, which MessageID is not guaranteed to be Aug 25, 2023
silouone added a commit that referenced this pull request Jun 19, 2026
…ueName fixes

- Serverless v4 logger migration (src/log.js shim threaded into the SQS emulator).
- Fix undefined this.region -> this.options.region so emitted events carry awsRegion. Re-implements #166 (thanks @zlalvani).
- Make SQS deleteMessageBatch entry Ids unique within a batch (index-based, <=80 chars). Re-implements #253 (thanks @flipscholtz).
- Add custom.serverless-offline-sqs.queueName override (non-mutating; strips arn so it wins for arn-bearing shapes). Re-implements #211 (thanks @mfamilia).
- Backward compatible with serverless v3. Adds docker-free unit tests. v8.1.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@silouone

Copy link
Copy Markdown
Member

Great catch @flipscholtz — since MessageId isn't guaranteed to be unique, the deleteMessageBatch entries needed distinct Ids, which is exactly what you fixed. This is now implemented in #265 (on master now, released shortly in the next release of serverless-offline-sqs), so I'll close this in favor of #265. Thank you for the contribution 🙏

@silouone silouone closed this Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants