fix(lambda): use persisted firstReceiveTimestamp in SQS ESM (#1548)

* fix: return XML error for missing action and add volume action fallbacks

* fix(eventbridge): sync EventBridge tags to ResourceGroupsTaggingService

EventBridge stored tags on rules, buses, and archives in its own stores but never propagated them to the central ResourceGroupsTaggingService. This caused GetResources with --resource-type-filters events:rule to return an empty list.

Inject ResourceGroupsTaggingService into EventBridgeService (following the existing GlueService pattern) and sync tags during putRule, tagResource, untagResource, and deleteRule operations.

Closes #1343

* fix(lambda): use persisted firstReceiveTimestamp in SQS ESM and Pipes event payloads

Both SqsEventSourcePoller.buildSqsEvent() and PipesPoller.buildSqsRecordNodes()
were using System.currentTimeMillis() for ApproximateFirstReceiveTimestamp,
causing the value to change on every poll cycle. AWS SQS defines this as the
epoch time when the message was first received from the queue, and it must
remain constant across retries.

The SQS service layer already tracks this correctly via
Message.firstReceiveTimestamp (set once in GuardedMessageQueue.tryClaim()),
but both pollers bypassed the stored value.

Changes:
- SqsEventSourcePoller: read msg.getFirstReceiveTimestamp() with null fallback
- PipesPoller: same fix for the identical code path
- SqsEventSourcePollerTest: set firstReceiveTimestamp on test messages and
  assert the output matches the stored value; add a regression test proving
  the timestamp remains stable across simulated retries

Closes #1497

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
Co-authored-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Konda Balaji RaoandHector Ventura authored and GitHub committed 2026-06-25 19:11:51 -05:00
1 parent 1a319551cc
commit 952dec060f
3 files changed
+40 -2

No files matched your search

@@ -63,9 +63,11 @@ class SqsEventSourcePollerTest {
@Test
void buildSqsEventIncludesAllRequiredAttributes() throws Exception {
Instant firstReceived = Instant.parse("2026-01-15T10:31:00Z");
Message msg = new Message();
msg.setBody("{\"key\":\"value\"}");
msg.setSentTimestamp(Instant.parse("2026-01-15T10:30:00Z"));
msg.setFirstReceiveTimestamp(firstReceived);
EventSourceMapping esm = new EventSourceMapping();
esm.setEventSourceArn("arn:aws:sqs:us-east-1:123456789012:my-queue");
@@ -84,6 +86,8 @@ class SqsEventSourcePollerTest {
assertEquals("123456789012", attrs.get("SenderId").asText());
assertEquals(String.valueOf(Instant.parse("2026-01-15T10:30:00Z").toEpochMilli()),
attrs.get("SentTimestamp").asText());
assertEquals(String.valueOf(firstReceived.toEpochMilli()),
attrs.get("ApproximateFirstReceiveTimestamp").asText());
assertEquals("aws:sqs", record.get("eventSource").asText());
assertEquals("arn:aws:sqs:us-east-1:123456789012:my-queue", record.get("eventSourceARN").asText());
assertEquals("us-east-1", record.get("awsRegion").asText());
@@ -280,6 +284,7 @@ class SqsEventSourcePollerTest {
msg.setReceiptHandle("rh-" + id);
msg.setBody("body-" + id);
msg.setSentTimestamp(Instant.now());
msg.setFirstReceiveTimestamp(Instant.now());
return msg;
}
@@ -362,4 +367,31 @@ class SqsEventSourcePollerTest {
verify(sqsService, timeout(2000)).deleteMessage(esm.getQueueUrl(), "rh-m1", "us-east-1");
verify(sqsService, never()).changeMessageVisibility(any(), any(), anyInt(), any());
}
@Test
void firstReceiveTimestampRemainsStableAcrossRetries() throws Exception {
Instant firstReceived = Instant.parse("2026-01-15T10:31:00Z");
Message msg = new Message();
msg.setBody("retry-body");
msg.setSentTimestamp(Instant.parse("2026-01-15T10:30:00Z"));
msg.setFirstReceiveTimestamp(firstReceived);
msg.setReceiveCount(3);
EventSourceMapping esm = new EventSourceMapping();
esm.setEventSourceArn("arn:aws:sqs:us-east-1:000000000000:test-queue");
esm.setRegion("us-east-1");
String firstCall = poller.buildSqsEvent(List.of(msg), esm);
Thread.sleep(10);
String secondCall = poller.buildSqsEvent(List.of(msg), esm);
JsonNode firstTs = OBJECT_MAPPER.readTree(firstCall)
.get("Records").get(0).get("attributes").get("ApproximateFirstReceiveTimestamp");
JsonNode secondTs = OBJECT_MAPPER.readTree(secondCall)
.get("Records").get(0).get("attributes").get("ApproximateFirstReceiveTimestamp");
assertEquals(String.valueOf(firstReceived.toEpochMilli()), firstTs.asText());
assertEquals(firstTs.asText(), secondTs.asText(),
"ApproximateFirstReceiveTimestamp must not change between retries");
}
}