fix(lambda): populate SQS messageAttributes in Lambda event payload (#1422)

* 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): populate SQS messageAttributes in Lambda event payload

buildSqsEvent() was calling record.putObject("messageAttributes") which
creates an empty JSON object node and discards msg.getMessageAttributes()
entirely. Lambda functions receiving SQS events always saw an empty
messageAttributes map regardless of what was sent with the message.

Fix serializes each MessageAttributeValue into the AWS-specified shape:
  { dataType, stringValue, binaryValue, stringListValues, binaryListValues }

Binary values are base64-encoded per the Lambda SQS event contract.
md5OfMessageAttributes is now forwarded to the record when present.

Added four new unit tests covering: String, Number, and Binary attribute
types, multiple messages each with independent attributes, and the
no-attributes case (backward compat: empty object, no md5 field).

Fixes #1411

* fix: serialize only populated SQS message attribute values

* fix: omit null scalar fields from SQS message attributes in Lambda event payload

- Stop emitting explicit JSON nulls for absent stringValue/binaryValue
  fields in SqsEventSourcePoller.buildSqsEvent(); AWS Lambda omits
  these entirely rather than sending null.
- Align serialization order with PipesPoller: check binaryValue first,
  then stringValue via else-if.
- Update test assertions to expect key-absent (assertNull) instead of
  null-JSON-node (isNull) for the unpopulated scalar field.
This commit is contained in:
Konda Balaji Rao authored and GitHub committed 2026-06-24 23:37:03 -05:00
1 parent e8f7cc470e
commit a3f3bf8fe1
3 files changed
+137 -2

No files matched your search

@@ -87,6 +87,122 @@ class SqsEventSourcePollerTest {
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());
// message with no attributes — messageAttributes must be an empty object, not absent
assertTrue(record.get("messageAttributes").isObject());
assertEquals(0, record.get("messageAttributes").size());
assertNull(record.get("md5OfMessageAttributes"));
}
@Test
void buildSqsEventPopulatesStringMessageAttribute() throws Exception {
Message msg = new Message();
msg.setBody("hello");
msg.setSentTimestamp(Instant.now());
io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue attr =
new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue("red", "String");
msg.getMessageAttributes().put("color", attr);
msg.updateMd5OfMessageAttributes();
EventSourceMapping esm = new EventSourceMapping();
esm.setEventSourceArn("arn:aws:sqs:us-east-1:123456789012:test-queue");
esm.setRegion("us-east-1");
String event = poller.buildSqsEvent(List.of(msg), esm);
JsonNode record = OBJECT_MAPPER.readTree(event).get("Records").get(0);
JsonNode msgAttrs = record.get("messageAttributes");
assertTrue(msgAttrs.isObject(), "messageAttributes must be an object");
assertEquals(1, msgAttrs.size());
JsonNode color = msgAttrs.get("color");
assertNotNull(color, "color attribute must be present");
assertEquals("String", color.get("dataType").asText());
assertEquals("red", color.get("stringValue").asText());
assertNull(color.get("binaryValue"));
assertTrue(color.get("stringListValues").isArray());
assertTrue(color.get("binaryListValues").isArray());
// md5OfMessageAttributes must be propagated to the record
assertNotNull(record.get("md5OfMessageAttributes"),
"md5OfMessageAttributes must be present when attributes exist");
}
@Test
void buildSqsEventPopulatesNumberMessageAttribute() throws Exception {
Message msg = new Message();
msg.setBody("order");
msg.setSentTimestamp(Instant.now());
io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue attr =
new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue("42", "Number");
msg.getMessageAttributes().put("count", attr);
EventSourceMapping esm = new EventSourceMapping();
esm.setEventSourceArn("arn:aws:sqs:us-east-1:123456789012:num-queue");
esm.setRegion("us-east-1");
String event = poller.buildSqsEvent(List.of(msg), esm);
JsonNode color = OBJECT_MAPPER.readTree(event)
.get("Records").get(0).get("messageAttributes").get("count");
assertEquals("Number", color.get("dataType").asText());
assertEquals("42", color.get("stringValue").asText());
}
@Test
void buildSqsEventPopulatesBinaryMessageAttribute() throws Exception {
Message msg = new Message();
msg.setBody("bin");
msg.setSentTimestamp(Instant.now());
byte[] raw = {1, 2, 3};
io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue attr =
new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue(raw, "Binary");
msg.getMessageAttributes().put("data", attr);
EventSourceMapping esm = new EventSourceMapping();
esm.setEventSourceArn("arn:aws:sqs:us-east-1:123456789012:bin-queue");
esm.setRegion("us-east-1");
String event = poller.buildSqsEvent(List.of(msg), esm);
JsonNode data = OBJECT_MAPPER.readTree(event)
.get("Records").get(0).get("messageAttributes").get("data");
assertEquals("Binary", data.get("dataType").asText());
assertNull(data.get("stringValue"));
assertEquals(
java.util.Base64.getEncoder().encodeToString(raw),
data.get("binaryValue").asText());
}
@Test
void buildSqsEventHandlesMultipleAttributesAcrossMultipleMessages() throws Exception {
io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue a1 =
new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue("v1", "String");
io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue a2 =
new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue("v2", "String");
Message msg1 = new Message();
msg1.setBody("m1");
msg1.setSentTimestamp(Instant.now());
msg1.getMessageAttributes().put("attr1", a1);
Message msg2 = new Message();
msg2.setBody("m2");
msg2.setSentTimestamp(Instant.now());
msg2.getMessageAttributes().put("attr2", a2);
EventSourceMapping esm = new EventSourceMapping();
esm.setEventSourceArn("arn:aws:sqs:us-east-1:123456789012:multi-queue");
esm.setRegion("us-east-1");
String event = poller.buildSqsEvent(List.of(msg1, msg2), esm);
JsonNode records = OBJECT_MAPPER.readTree(event).get("Records");
assertEquals("v1", records.get(0).get("messageAttributes").get("attr1").get("stringValue").asText());
assertEquals("v2", records.get(1).get("messageAttributes").get("attr2").get("stringValue").asText());
}
@Test