fix(lambda): propagate SQS FIFO system attributes to ESM event (#1527)

When an SQS event source mapping invokes a Lambda from a FIFO queue,
copy MessageGroupId, SequenceNumber, and MessageDeduplicationId into
each record's attributes map, matching the values ReceiveMessage
already returns. Standard-queue messages are unaffected.

Closes #1526
This commit is contained in:
Stuart Lang authored and GitHub committed 2026-06-25 18:06:44 -05:00
1 parent 0a806f7382
commit 21a7939e46
2 files changed
+49

No files matched your search

@@ -205,6 +205,46 @@ class SqsEventSourcePollerTest {
assertEquals("v2", records.get(1).get("messageAttributes").get("attr2").get("stringValue").asText());
}
@Test
void buildSqsEventIncludesFifoSystemAttributes() throws Exception {
Message msg = new Message();
msg.setBody("hello-fifo");
msg.setSentTimestamp(Instant.parse("2026-01-15T10:30:00Z"));
msg.setMessageGroupId("groupA");
msg.setSequenceNumber(27);
msg.setMessageDeduplicationId("6e809cbda0732ac4845916a59016f954");
EventSourceMapping esm = new EventSourceMapping();
esm.setEventSourceArn("arn:aws:sqs:us-east-1:123456789012:my-queue.fifo");
esm.setRegion("us-east-1");
String event = poller.buildSqsEvent(List.of(msg), esm);
JsonNode attrs = OBJECT_MAPPER.readTree(event).get("Records").get(0).get("attributes");
assertEquals("groupA", attrs.get("MessageGroupId").asText());
assertEquals("27", attrs.get("SequenceNumber").asText());
assertEquals("6e809cbda0732ac4845916a59016f954",
attrs.get("MessageDeduplicationId").asText());
}
@Test
void buildSqsEventOmitsFifoSystemAttributesForStandardQueueMessages() throws Exception {
Message msg = new Message();
msg.setBody("hello");
msg.setSentTimestamp(Instant.parse("2026-01-15T10:30:00Z"));
EventSourceMapping esm = new EventSourceMapping();
esm.setEventSourceArn("arn:aws:sqs:us-east-1:123456789012:my-queue");
esm.setRegion("us-east-1");
String event = poller.buildSqsEvent(List.of(msg), esm);
JsonNode attrs = OBJECT_MAPPER.readTree(event).get("Records").get(0).get("attributes");
assertNull(attrs.get("MessageGroupId"));
assertNull(attrs.get("SequenceNumber"));
assertNull(attrs.get("MessageDeduplicationId"));
}
@Test
void buildSqsEventUsesDefaultAccountWhenArnParsingFails() throws Exception {
Message msg = new Message();