feat(ses): publish events to Firehose, EventBridge, CloudWatch (#1188)

* feat(ses): publish events to Firehose, EventBridge, and CloudWatch destinations

Extend SES V2 configuration set event publishing so destinations beyond
SnsDestination actually deliver. Previously KinesisFirehoseDestination,
EventBridgeDestination, and CloudWatchDestination were stored but the
publisher logged a warning and skipped. PinpointDestination still skips.

- KinesisFirehoseDestination → single Firehose PutRecord per event;
  S3-backed streams flush accumulated records as NDJSON once the default
  count threshold is reached.
- EventBridgeDestination → PutEvents entry with Source=aws.ses,
  DetailType="Email <EventTypeLabel>", payload as Detail. Region is
  stamped on the entry (so matchesPattern + envelope agree on a
  non-default region) and Resources is always present (empty when
  sourceArn is null — matchesPattern's resources-filter branch casts
  entry.get("Resources") unconditionally).
- CloudWatchDestination → MetricDatum to AWS/SES with Unit=Count.
  Dimensions resolved from DimensionConfigurations against EmailTags
  (MESSAGE_TAG / messageTag), email headers (EMAIL_HEADER / emailHeader),
  or ses:configuration-set, falling back to DefaultDimensionValue.
  Timestamp left to putMetricData's epoch-seconds default.

Tests
- SesEventPublishingV2IntegrationTest @Order 14-28: per-destination
  setup → send → assert, plus a cross-region (eu-west-1) EventBridge
  case pinning region propagation end-to-end.
- SesEventPublisherTest (Mockito ArgumentCaptor): the EB PutEvents
  entry always carries Resources as an ArrayNode — integration tests
  cannot pin this because EventBridgeService.buildEventEnvelope
  defaults a missing key via getOrDefault.

Docs
- docs/services/ses.md: replace the SNS-only claim with the four
  supported destination types.

* fix(ses): use AWS past-tense detail-type for EventBridge SES events

The EventBridge publisher was emitting "Email Send", "Email Delivery",
etc — derived from the SNS notification eventType vocabulary by
prepending "Email ". AWS uses a separate past-tense vocabulary on
EventBridge: "Email Sent", "Email Delivered", "Email Bounced", "Email
Complaint Received", "Email Rejected", "Email Opened", "Email Clicked",
"Email Rendering Failed", "Email Delivery Delayed", "Email Subscribed"
(see https://docs.aws.amazon.com/eventbridge/latest/ref/events-ref-ses.html).

A customer rule pattern keyed on the AWS value
({"source":["aws.ses"],"detail-type":["Email Delivered"]}) would
silently fail to match Floci events.

Changes:
- Add SesEventPayload.eventBridgeDetailType returning the past-tense
  EventBridge vocabulary. Kept separate from eventTypeLabel (which
  remains correct for SNS notifications and CloudWatch metric names).
- SesEventPublisher.publishEventBridge uses the new mapping.

Tests
- SesEventPayloadTest.eventBridgeDetailType_matchesAwsPastTenseVocabulary:
  pins all 10 mappings against AWS docs.
- SesEventPublishingV2IntegrationTest @Order 29
  (eventBridge_detailTypePattern_keyedOnAwsSentValue_matches):
  structural pin — creates a rule with EventPattern
  {"source":["aws.ses"],"detail-type":["Email Sent"]} and asserts the
  SQS target receives the SEND envelope. A regression to "Email Send"
  would cause the rule to silently drop the event, failing the test
  without relying on any hard-coded assertion string.
- Existing tests updated to assert the AWS values:
  SesEventPublishingV2IntegrationTest 4 assertions; sdk-test-java
  SesEventPublishingTest 3 assertions.

* fix(ses): emit CloudWatch metric name "RenderingFailure" without space

AWS CloudWatch metric publishing for SES uses "RenderingFailure" (no
space) for the RENDERING_FAILURE event type — verified against real
AWS by configuring a CW event destination on a configuration set,
sending a templated email with a missing TemplateData key to trigger
the rendering failure path, and capturing the new metric name from
`aws cloudwatch list-metrics --namespace AWS/SES`.

Floci's publisher was previously sourcing the CW MetricName from
SesEventPayload.eventTypeLabel, which returns "Rendering Failure" (with
space). That spelling is correct for the SNS notification's eventType
field but wrong for CloudWatch — customer dashboards / alarms keyed on
the AWS-correct "RenderingFailure" never see Floci's metric.

Changes:
- Add SesEventPayload.cloudWatchMetricName returning the CW spelling.
  Mirrors eventTypeLabel for every other case so the two stay aligned
  in shape; only RENDERING_FAILURE differs.
- SesEventPublisher.publishCloudWatch uses the new mapping.
- SesEventPayloadTest.cloudWatchMetricName_matchesAwsCwSpelling pins
  all 10 mappings; RENDERING_FAILURE expectation comes from the live
  AWS capture rather than an AWS docs guess.

DELIVERY_DELAY remains as "DeliveryDelay" in this commit — it could
not be triggered conveniently from the SES sandbox (needs genuine SES
backoff), so leaving the existing value rather than guessing. Flagged
in code comments as needing future verification.

The other simple metric names (Send, Delivery, Bounce, Complaint) were
also verified against the same AWS capture and match Floci's existing
spelling byte-for-byte — no change needed for those.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-06-09 00:36:28 -05:00
1 parent 3065774e80
commit 35f597addd
7 files changed
+1893 -31

No files matched your search

@@ -33,6 +33,11 @@ import software.amazon.awssdk.services.sesv2.model.SendBulkEmailRequest;
import software.amazon.awssdk.services.sesv2.model.SendEmailRequest;
import software.amazon.awssdk.services.sesv2.model.SnsDestination;
import software.amazon.awssdk.services.sesv2.model.Template;
import software.amazon.awssdk.services.sesv2.model.CloudWatchDestination;
import software.amazon.awssdk.services.sesv2.model.CloudWatchDimensionConfiguration;
import software.amazon.awssdk.services.sesv2.model.DimensionValueSource;
import software.amazon.awssdk.services.sesv2.model.EventBridgeDestination;
import software.amazon.awssdk.services.sesv2.model.KinesisFirehoseDestination;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.CreateTopicRequest;
@@ -50,18 +55,48 @@ import software.amazon.awssdk.services.sqs.model.QueueAttributeName;
import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest;
import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse;
import software.amazon.awssdk.services.firehose.FirehoseClient;
import software.amazon.awssdk.services.firehose.model.CreateDeliveryStreamRequest;
import software.amazon.awssdk.services.firehose.model.DeleteDeliveryStreamRequest;
import software.amazon.awssdk.services.firehose.model.S3DestinationConfiguration;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
import software.amazon.awssdk.services.s3.model.DeleteBucketRequest;
import software.amazon.awssdk.services.s3.model.DeleteObjectsRequest;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
import software.amazon.awssdk.services.s3.model.ObjectIdentifier;
import software.amazon.awssdk.services.s3.model.S3Object;
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
import software.amazon.awssdk.services.eventbridge.model.DeleteRuleRequest;
import software.amazon.awssdk.services.eventbridge.model.PutRuleRequest;
import software.amazon.awssdk.services.eventbridge.model.PutTargetsRequest;
import software.amazon.awssdk.services.eventbridge.model.RemoveTargetsRequest;
import software.amazon.awssdk.services.eventbridge.model.Target;
import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
import software.amazon.awssdk.services.cloudwatch.model.ListMetricsRequest;
import software.amazon.awssdk.services.cloudwatch.model.Metric;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
/**
* SES event-publishing compatibility tests using the AWS SDK for Java v2.
*
* Drives the entire flow through real SDK clients (SesV2Client / SnsClient /
* SqsClient): create a configuration set + SNS event destination, send via
* SesV2Client.SendEmail with ConfigurationSetName, then receive the resulting
* SES event JSON from a subscribed SQS queue and assert the AWS-format shape.
* Drives the entire flow through real SDK clients (SesV2Client + SnsClient /
* FirehoseClient + S3Client / EventBridgeClient + SqsClient / CloudWatchClient):
* create a configuration set per destination type, send via SesV2Client.SendEmail
* with the ConfigurationSetName, then assert the AWS-format event JSON shape at
* each destination's natural sink — SNS-subscribed SQS, S3 (Firehose flush),
* EventBridge rule's SQS target, and CloudWatch metric registration.
*/
@DisplayName("SES Event Publishing")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@@ -69,24 +104,48 @@ class SesEventPublishingTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final String EVENT_DEST_NAME = "ed-sns";
private static final String EVENT_DEST_NAME_FIREHOSE = "ed-firehose";
private static final String EVENT_DEST_NAME_EB = "ed-eventbridge";
private static final String EVENT_DEST_NAME_CW = "ed-cloudwatch";
private static SesV2Client ses;
private static SnsClient sns;
private static SqsClient sqs;
private static FirehoseClient firehose;
private static S3Client s3;
private static EventBridgeClient eventBridge;
private static CloudWatchClient cloudWatch;
private static String csName;
private static String csNameFirehose;
private static String csNameEB;
private static String csNameCW;
private static String identity;
private static String queueUrl;
private static String queueArn;
private static String topicArn;
private static String subscriptionArn;
private static String firehoseStreamName;
private static String firehoseStreamArn;
private static String firehoseBucket;
private static String ebQueueUrl;
private static String ebQueueArn;
private static String ebRuleName;
private static String ebBusArn;
@BeforeAll
static void setup() {
ses = TestFixtures.sesV2Client();
sns = TestFixtures.snsClient();
sqs = TestFixtures.sqsClient();
firehose = TestFixtures.firehoseClient();
s3 = TestFixtures.s3Client();
eventBridge = TestFixtures.eventBridgeClient();
cloudWatch = TestFixtures.cloudWatchClient();
String suffix = TestFixtures.uniqueName();
csName = "sdk-evt-cs-" + suffix;
csNameFirehose = "sdk-evt-cs-fh-" + suffix;
csNameEB = "sdk-evt-cs-eb-" + suffix;
csNameCW = "sdk-evt-cs-cw-" + suffix;
identity = "sdk-evt-from-" + suffix + "@floci.test";
queueUrl = sqs.createQueue(CreateQueueRequest.builder()
@@ -129,22 +188,122 @@ class SesEventPublishingTest {
.snsDestination(SnsDestination.builder().topicArn(topicArn).build())
.build())
.build());
// Firehose destination plumbing: S3 bucket + delivery stream + CS + Firehose dest.
firehoseBucket = "sdk-evt-fh-bucket-" + suffix;
s3.createBucket(CreateBucketRequest.builder().bucket(firehoseBucket).build());
firehoseStreamName = "sdk-evt-fh-stream-" + suffix;
firehoseStreamArn = firehose.createDeliveryStream(CreateDeliveryStreamRequest.builder()
.deliveryStreamName(firehoseStreamName)
.s3DestinationConfiguration(S3DestinationConfiguration.builder()
.bucketARN("arn:aws:s3:::" + firehoseBucket)
.roleARN("arn:aws:iam::000000000000:role/sdk-evt-fh-role")
.build())
.build())
.deliveryStreamARN();
ses.createConfigurationSet(CreateConfigurationSetRequest.builder()
.configurationSetName(csNameFirehose)
.build());
ses.createConfigurationSetEventDestination(CreateConfigurationSetEventDestinationRequest.builder()
.configurationSetName(csNameFirehose)
.eventDestinationName(EVENT_DEST_NAME_FIREHOSE)
.eventDestination(EventDestinationDefinition.builder()
.enabled(true)
.matchingEventTypes(EventType.SEND)
.kinesisFirehoseDestination(KinesisFirehoseDestination.builder()
.iamRoleArn("arn:aws:iam::000000000000:role/sdk-evt-fh-role")
.deliveryStreamArn(firehoseStreamArn)
.build())
.build())
.build());
// EventBridge destination plumbing: SQS target + rule on default bus + CS + EB dest.
ebQueueUrl = sqs.createQueue(CreateQueueRequest.builder()
.queueName("sdk-evt-eb-q-" + suffix)
.build())
.queueUrl();
ebQueueArn = sqs.getQueueAttributes(GetQueueAttributesRequest.builder()
.queueUrl(ebQueueUrl)
.attributeNames(QueueAttributeName.QUEUE_ARN)
.build())
.attributes().get(QueueAttributeName.QUEUE_ARN);
ebRuleName = "sdk-evt-eb-rule-" + suffix;
eventBridge.putRule(PutRuleRequest.builder()
.name(ebRuleName)
.eventPattern("{\"source\":[\"aws.ses\"]}")
.build());
eventBridge.putTargets(PutTargetsRequest.builder()
.rule(ebRuleName)
.targets(Target.builder().id("1").arn(ebQueueArn).build())
.build());
ebBusArn = "arn:aws:events:us-east-1:000000000000:event-bus/default";
ses.createConfigurationSet(CreateConfigurationSetRequest.builder()
.configurationSetName(csNameEB)
.build());
ses.createConfigurationSetEventDestination(CreateConfigurationSetEventDestinationRequest.builder()
.configurationSetName(csNameEB)
.eventDestinationName(EVENT_DEST_NAME_EB)
.eventDestination(EventDestinationDefinition.builder()
.enabled(true)
.matchingEventTypes(EventType.SEND, EventType.DELIVERY)
.eventBridgeDestination(EventBridgeDestination.builder()
.eventBusArn(ebBusArn)
.build())
.build())
.build());
// CloudWatch destination plumbing: CS + CW dest with three dimension configs.
ses.createConfigurationSet(CreateConfigurationSetRequest.builder()
.configurationSetName(csNameCW)
.build());
ses.createConfigurationSetEventDestination(CreateConfigurationSetEventDestinationRequest.builder()
.configurationSetName(csNameCW)
.eventDestinationName(EVENT_DEST_NAME_CW)
.eventDestination(EventDestinationDefinition.builder()
.enabled(true)
.matchingEventTypes(EventType.SEND, EventType.DELIVERY)
.cloudWatchDestination(CloudWatchDestination.builder()
.dimensionConfigurations(
CloudWatchDimensionConfiguration.builder()
.dimensionName("ses:configuration-set")
.dimensionValueSource(DimensionValueSource.MESSAGE_TAG)
.defaultDimensionValue("unknown")
.build(),
CloudWatchDimensionConfiguration.builder()
.dimensionName("campaign")
.dimensionValueSource(DimensionValueSource.MESSAGE_TAG)
.defaultDimensionValue("default-campaign")
.build(),
CloudWatchDimensionConfiguration.builder()
.dimensionName("X-Custom-Header")
.dimensionValueSource(DimensionValueSource.EMAIL_HEADER)
.defaultDimensionValue("default-header")
.build())
.build())
.build())
.build());
}
@AfterAll
static void cleanup() {
if (ses != null) {
try {
ses.deleteConfigurationSetEventDestination(DeleteConfigurationSetEventDestinationRequest.builder()
.configurationSetName(csName)
.eventDestinationName(EVENT_DEST_NAME)
.build());
} catch (Exception ignored) {}
try {
ses.deleteConfigurationSet(DeleteConfigurationSetRequest.builder()
.configurationSetName(csName)
.build());
} catch (Exception ignored) {}
for (String[] pair : new String[][]{
{csName, EVENT_DEST_NAME},
{csNameFirehose, EVENT_DEST_NAME_FIREHOSE},
{csNameEB, EVENT_DEST_NAME_EB},
{csNameCW, EVENT_DEST_NAME_CW}}) {
try {
ses.deleteConfigurationSetEventDestination(DeleteConfigurationSetEventDestinationRequest.builder()
.configurationSetName(pair[0])
.eventDestinationName(pair[1])
.build());
} catch (Exception ignored) {}
try {
ses.deleteConfigurationSet(DeleteConfigurationSetRequest.builder()
.configurationSetName(pair[0])
.build());
} catch (Exception ignored) {}
}
try {
ses.deleteEmailIdentity(DeleteEmailIdentityRequest.builder()
.emailIdentity(identity)
@@ -161,12 +320,53 @@ class SesEventPublishingTest {
} catch (Exception ignored) {}
sns.close();
}
if (eventBridge != null) {
try {
eventBridge.removeTargets(RemoveTargetsRequest.builder()
.rule(ebRuleName).ids("1").build());
} catch (Exception ignored) {}
try {
eventBridge.deleteRule(DeleteRuleRequest.builder().name(ebRuleName).build());
} catch (Exception ignored) {}
eventBridge.close();
}
if (sqs != null) {
try {
sqs.deleteQueue(DeleteQueueRequest.builder().queueUrl(queueUrl).build());
} catch (Exception ignored) {}
try {
sqs.deleteQueue(DeleteQueueRequest.builder().queueUrl(ebQueueUrl).build());
} catch (Exception ignored) {}
sqs.close();
}
if (firehose != null) {
try {
firehose.deleteDeliveryStream(DeleteDeliveryStreamRequest.builder()
.deliveryStreamName(firehoseStreamName).build());
} catch (Exception ignored) {}
firehose.close();
}
if (s3 != null) {
try {
ListObjectsV2Response listed = s3.listObjectsV2(ListObjectsV2Request.builder()
.bucket(firehoseBucket).build());
if (!listed.contents().isEmpty()) {
s3.deleteObjects(DeleteObjectsRequest.builder()
.bucket(firehoseBucket)
.delete(d -> d.objects(listed.contents().stream()
.map(o -> ObjectIdentifier.builder().key(o.key()).build())
.collect(Collectors.toList())))
.build());
}
} catch (Exception ignored) {}
try {
s3.deleteBucket(DeleteBucketRequest.builder().bucket(firehoseBucket).build());
} catch (Exception ignored) {}
s3.close();
}
if (cloudWatch != null) {
cloudWatch.close();
}
}
@Test
@@ -275,6 +475,204 @@ class SesEventPublishingTest {
.isEqualTo("override");
}
@Test
@Order(5)
@DisplayName("Firehose destination: 5 sends trigger auto-flush to S3 as NDJSON")
void firehoseDestination_fiveSends_triggerAutoFlushToS3() throws Exception {
for (int i = 0; i < 5; i++) {
ses.sendEmail(SendEmailRequest.builder()
.fromEmailAddress(identity)
.destination(Destination.builder()
.toAddresses("fh-recipient" + i + "@example.com")
.build())
.configurationSetName(csNameFirehose)
.content(EmailContent.builder()
.simple(Message.builder()
.subject(Content.builder().data("fh-evt-" + i).build())
.body(Body.builder()
.text(Content.builder().data("hi").build())
.build())
.build())
.build())
.build());
}
ListObjectsV2Response listed = s3.listObjectsV2(ListObjectsV2Request.builder()
.bucket(firehoseBucket)
.prefix(firehoseStreamName + "/")
.build());
assertThat(listed.contents())
.as("Firehose should have flushed exactly one S3 object after 5 records")
.hasSize(1);
S3Object obj = listed.contents().get(0);
String body = new String(s3.getObject(GetObjectRequest.builder()
.bucket(firehoseBucket).key(obj.key()).build())
.readAllBytes(), StandardCharsets.UTF_8);
String[] lines = body.split("\\R");
assertThat(lines).hasSize(5);
for (String line : lines) {
JsonNode event = MAPPER.readTree(line);
assertThat(event.path("eventType").asText()).isEqualTo("Send");
assertThat(event.path("mail").path("source").asText()).isEqualTo(identity);
assertThat(event.path("mail").path("tags").path("ses:configuration-set").get(0).asText())
.isEqualTo(csNameFirehose);
}
}
@Test
@Order(6)
@DisplayName("EventBridge destination: regular recipient routes Email Send to SQS via rule")
void eventBridgeDestination_regularRecipient_routesEmailSendToSqs() throws Exception {
drainEbQueue();
ses.sendEmail(SendEmailRequest.builder()
.fromEmailAddress(identity)
.destination(Destination.builder().toAddresses("eb-recipient@example.com").build())
.configurationSetName(csNameEB)
.content(EmailContent.builder()
.simple(Message.builder()
.subject(Content.builder().data("eb-evt").build())
.body(Body.builder()
.text(Content.builder().data("hi").build())
.build())
.build())
.build())
.build());
List<JsonNode> envelopes = receiveEbEvents(1);
assertThat(envelopes).hasSize(1);
JsonNode env = envelopes.get(0);
assertThat(env.path("source").asText()).isEqualTo("aws.ses");
assertThat(env.path("detail-type").asText()).isEqualTo("Email Sent");
JsonNode detail = env.path("detail");
assertThat(detail.path("eventType").asText()).isEqualTo("Send");
assertThat(detail.path("mail").path("source").asText()).isEqualTo(identity);
assertThat(detail.path("mail").path("tags").path("ses:configuration-set").get(0).asText())
.isEqualTo(csNameEB);
}
@Test
@Order(7)
@DisplayName("EventBridge destination: success simulator routes both Email Send and Email Delivery")
void eventBridgeDestination_successSimulator_routesSendAndDelivery() throws Exception {
drainEbQueue();
ses.sendEmail(SendEmailRequest.builder()
.fromEmailAddress(identity)
.destination(Destination.builder()
.toAddresses("success@simulator.amazonses.com").build())
.configurationSetName(csNameEB)
.content(EmailContent.builder()
.simple(Message.builder()
.subject(Content.builder().data("eb-evt-success").build())
.body(Body.builder()
.text(Content.builder().data("hi").build())
.build())
.build())
.build())
.build());
List<JsonNode> envelopes = receiveEbEvents(2);
assertThat(envelopes).hasSize(2);
assertThat(envelopes).anyMatch(e -> "Email Sent".equals(e.path("detail-type").asText()));
assertThat(envelopes).anyMatch(e -> "Email Delivered".equals(e.path("detail-type").asText()));
}
@Test
@Order(8)
@DisplayName("CloudWatch destination: send registers AWS/SES Send metric with resolved dimensions")
void cloudWatchDestination_registersSendMetricWithResolvedDimensions() {
ses.sendEmail(SendEmailRequest.builder()
.fromEmailAddress(identity)
.destination(Destination.builder().toAddresses("cw-recipient@example.com").build())
.configurationSetName(csNameCW)
.emailTags(MessageTag.builder().name("campaign").value("launch").build())
.content(EmailContent.builder()
.simple(Message.builder()
.subject(Content.builder().data("cw-evt").build())
.body(Body.builder()
.text(Content.builder().data("hi").build())
.build())
.headers(MessageHeader.builder()
.name("X-Custom-Header").value("header-value").build())
.build())
.build())
.build());
List<Metric> sendMetrics = cloudWatch.listMetrics(ListMetricsRequest.builder()
.namespace("AWS/SES")
.metricName("Send")
.build())
.metrics();
assertThat(sendMetrics)
.as("expected at least one Send metric in AWS/SES")
.isNotEmpty();
assertThat(sendMetrics).anyMatch(m ->
m.dimensions().stream()
.anyMatch(d -> "ses:configuration-set".equals(d.name())
&& csNameCW.equals(d.value()))
&& m.dimensions().stream()
.anyMatch(d -> "campaign".equals(d.name()) && "launch".equals(d.value()))
&& m.dimensions().stream()
.anyMatch(d -> "X-Custom-Header".equals(d.name())
&& "header-value".equals(d.value())));
}
private void drainEbQueue() {
for (int i = 0; i < 5; i++) {
ReceiveMessageResponse r = sqs.receiveMessage(ReceiveMessageRequest.builder()
.queueUrl(ebQueueUrl)
.maxNumberOfMessages(10)
.waitTimeSeconds(0)
.build());
if (r.messages().isEmpty()) {
return;
}
List<DeleteMessageBatchRequestEntry> entries = new ArrayList<>();
for (int j = 0; j < r.messages().size(); j++) {
entries.add(DeleteMessageBatchRequestEntry.builder()
.id("m" + j)
.receiptHandle(r.messages().get(j).receiptHandle())
.build());
}
sqs.deleteMessageBatch(DeleteMessageBatchRequest.builder()
.queueUrl(ebQueueUrl)
.entries(entries)
.build());
}
}
private List<JsonNode> receiveEbEvents(int expectedAtLeast) throws Exception {
List<JsonNode> events = new ArrayList<>();
for (int attempt = 0; attempt < 10; attempt++) {
if (events.size() >= expectedAtLeast) {
break;
}
ReceiveMessageResponse r = sqs.receiveMessage(ReceiveMessageRequest.builder()
.queueUrl(ebQueueUrl)
.maxNumberOfMessages(10)
.waitTimeSeconds(1)
.build());
if (r.messages().isEmpty()) {
continue;
}
for (var m : r.messages()) {
events.add(MAPPER.readTree(m.body()));
}
List<DeleteMessageBatchRequestEntry> entries = new ArrayList<>();
for (int j = 0; j < r.messages().size(); j++) {
entries.add(DeleteMessageBatchRequestEntry.builder()
.id("m" + j)
.receiptHandle(r.messages().get(j).receiptHandle())
.build());
}
sqs.deleteMessageBatch(DeleteMessageBatchRequest.builder()
.queueUrl(ebQueueUrl)
.entries(entries)
.build());
}
return events;
}
private void sendEmailTo(String to) {
ses.sendEmail(SendEmailRequest.builder()
.fromEmailAddress(identity)