Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(sqs): return the current request's MD5s on a FIFO dedup hit (#2337)

Vanessa Hocd7ccd208281
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 37876ca2..0a3a47b3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **Route 53 — VPC associations for private hosted zones** — `AssociateVPCWithHostedZone`, `DisassociateVPCFromHostedZone` and `ListHostedZonesByVPC` (paged with `MaxItems` and `NextToken`). They refuse a public zone (`PublicZoneVPCAssociation`), a VPC already associated with a zone of the same name (`ConflictingDomainExists`), a VPC the zone doesn't have (404 `VPCAssociationNotFound`) and the zone's last VPC (`LastVPCAssociation`). Contributed by @kharabasz.
### Fixed
+- **SQS — FIFO dedup hit returns the current request's MD5s** — a `SendMessage` (or `SendMessageBatch` entry) whose `MessageDeduplicationId` was already in the 5-minute window answered with the first message's `MD5OfMessageBody` and `MD5OfMessageAttributes`; AWS keeps the first message but reports the digests of the request just sent, and SDKs that verify them (.NET, Java) threw `MD5 hash mismatch` on every replay whose body or attributes differed. The response now carries the current request's digests; `MessageId` and `SequenceNumber` are still the first message's. Contributed by @vanessah07.
- **S3 — `EU` location constraint** — since 1.5.28, `CreateBucket` from an eu-west-1 endpoint refused the legacy `EU` constraint with `IllegalLocationConstraintException`, and a bucket created with it elsewhere was homed in a region called `EU`. As on AWS, eu-west-1 now accepts `EU` and homes the bucket in eu-west-1, `GetBucketLocation` answers `EU` for it, and other regional endpoints still refuse it. The AWS SDK for .NET sends `EU` for eu-west-1 by default.
- **WAF v2 — `CreateIPSet` and `CreateRuleGroup` refuse a duplicate name** — a second IP set or rule group with the name and scope of an existing one is now refused with `WAFDuplicateItemException`, as AWS does and as `CreateWebACL` and `CreateRegexPatternSet` already did. Both stored the duplicate silently, so a client that retries a create after losing the response ended up with two. Contributed by @OS-kiranmalsetty.
- **Route 53 — private hosted zones keep their VPC** — `CreateHostedZone` with a `VPC` made a public zone and dropped the VPC, so Terraform's `aws_route53_zone` with a `vpc` block planned to add it again on every run; the zone is now private, the response carries the `VPC` instead of a delegation set, also on a `CallerReference` replay, and `GetHostedZone` returns its `VPCs`. Contributed by @kharabasz.
diff --git a/ministack/services/sqs.py b/ministack/services/sqs.py
index 42ebe3e2..d7eff488 100644
--- a/ministack/services/sqs.py
+++ b/ministack/services/sqs.py
@@ -691,10 +691,15 @@ def _act_send_message(data: dict, qurl: str) -> dict:
_prune_dedup(q)
cached = q["dedup_cache"].get(dedup_cache_key)
if cached:
+ # A dedup hit keeps the first message, but AWS answers with the
+ # digests of *this* request's body and attributes, not the first
+ # message's. SDKs that verify the digests (e.g. .NET, Java) reject
+ # a response that carries the cached ones.
r: dict = {"MessageId": cached["id"],
- "MD5OfMessageBody": cached["md5"]}
- if cached.get("md5a"):
- r["MD5OfMessageAttributes"] = cached["md5a"]
+ "MD5OfMessageBody": hashlib.md5(body_text.encode()).hexdigest()}
+ md5a_now = _md5_msg_attrs(msg_attrs)
+ if md5a_now:
+ r["MD5OfMessageAttributes"] = md5a_now
if cached.get("seq"):
r["SequenceNumber"] = cached["seq"]
return r
diff --git a/tests/test_sqs.py b/tests/test_sqs.py
index 0dca83c2..df65bdec 100644
--- a/tests/test_sqs.py
+++ b/tests/test_sqs.py
@@ -508,6 +508,43 @@ def test_sqs_fifo_deduplication(sqs):
)
assert r1["MessageId"] == r2["MessageId"]
+def test_sqs_fifo_dedup_hit_returns_md5_of_current_request(sqs):
+ """A dedup hit keeps the first message, but its response must carry the
+ MD5s of the request just sent, as AWS does. SDKs that verify the digests
+ (.NET, Java) reject a response that repeats the first message's."""
+ url = sqs.create_queue(
+ QueueName="intg-sqs-dedup-md5.fifo",
+ Attributes={"FifoQueue": "true", "ContentBasedDeduplication": "false"},
+ )["QueueUrl"]
+
+ def send(body, sent_at):
+ return sqs.send_message(
+ QueueUrl=url,
+ MessageBody=body,
+ MessageGroupId="g1",
+ MessageDeduplicationId="dedup-md5",
+ MessageAttributes={
+ "DateSent": {"DataType": "String", "StringValue": sent_at},
+ },
+ )
+
+ r1 = send("body-one", "2026-10-15T00:00:01Z")
+ r2 = send("body-one", "2026-10-15T00:00:02Z") # same body, new attribute
+ r3 = send("body-two", "2026-10-15T00:00:03Z") # new body and attribute
+
+ assert r1["MessageId"] == r2["MessageId"] == r3["MessageId"]
+ # Digests of the SQS binary encoding of each request's attributes.
+ assert r1["MD5OfMessageAttributes"] == "e9721848ab1db43af2ce7e25fce5d807"
+ assert r2["MD5OfMessageAttributes"] == "4079b5e9650ac7c7fd23793b2f8450d7"
+ assert r3["MD5OfMessageAttributes"] == "2a0cd9230604b4d3fcc365096e11817f"
+ assert r1["MD5OfMessageBody"] == r2["MD5OfMessageBody"] == "58bc92401b7ad098acdab54fad72e79a"
+ assert r3["MD5OfMessageBody"] == "6423099901cb7ed39e2a7a6517162e8d"
+
+ attrs = sqs.get_queue_attributes(QueueUrl=url, AttributeNames=["ApproximateNumberOfMessages"])
+ assert attrs["Attributes"]["ApproximateNumberOfMessages"] == "1"
+ sqs.delete_queue(QueueUrl=url)
+
+
def test_sqs_fifo_dedup_survives_consumption(sqs):
"""A FIFO dedup id is honored for its full 5-minute window even after the
original message is received and deleted — the Lambda-ESM consume pattern