I’m using the AWS Java SDK 2 with Java 17 on Windows 10. I have my AWS credentials configured correctly for the CLI/SDK/etc. On my local machine I’m testing sending an event to EventBridge. Using the EventBridge examples using SDK for Java 2.x I created extremely simple code like this:
Region region = Region.…; //matches my AWS configuration default region
EventBridgeClient eventBridgeClient = EventBridgeClient.builder().region(region).build();
String json = "{"Message": "This event was generated by example code."}";
PutEventsRequestEntry entry = PutEventsRequestEntry.builder()
.source(MyEmitter.class.getSimpleName())
.detail(json)
.detailType(MyDAO.class.getSimpleName())
.build();
Notice that I forgot to even indicate an event bus name. And because I didn’t specify an endpoint, I expected it to fail (thinking that I had to point it to a local EventBridge instance, not considering that it might just connect to the real AWS by default).
I ran this and it succeeded! But where did the event go? Did it go to the account default EventBridge bus? I logged into the AWS console and went to CloudTrail, but I don’t see any EventBridge events. According to Log and monitor in Amazon EventBridge:
CloudTrail is enabled on your AWS account when you create your account. When an event occurs in EventBridge, CloudTrail records the event in Event history.
This sounds like logging of EventBridge events happens automatically, but I don’t see any of them. Am I looking in the right place?
Where did the AWS Java SDK send the EventBridge event which apparently succeeded, and where can I find a record of this?
2
Answers
Answering my own questions:
Yes, if you don't specify an event bus in the AWS SDK, apparently it sends the event to the account default event bus.
Apparently the automatic logging of events happens automatically for AWS service events, but not for custom events.
To see custom events, follow the directions in Event-driven with EventBridge > First event bus and targets > Step 2: Set up Amazon CloudWatch target (for development work) to set up a catch-all rule to log custom events to a CloudWatch log group.
{"source": ["MyEmmitter"]}
(to match events with a source as shown in this question.Run the code in the question again and then go to the CloudWatch log group you indicated; you can see the event there.
For anyone reading this thread and looking for additional Amazon EventBridge examples, there is a detailed Java V2 example that performs these tasks:
See this example in the AWS Code Library:
Get started with EventBridge rules and targets using an AWS SDK