skip to Main Content

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


  1. Chosen as BEST ANSWER

    Answering my own questions:

    I ran this and it succeeded! But where did the event go? Did it go to the account default EventBridge bus?

    Yes, if you don't specify an event bus in the AWS SDK, apparently it sends the event to the account default event bus.

    I logged into the AWS console and went to CloudTrail, but I don't see any EventBridge events. [The documentation] like logging of EventBridge events happens automatically, but I don't see any of them.

    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.

    • Select an event source of "Other" (Custom events or events sent from more than one source, e.g. events from AWS services and partners.)
    • Specify an event pattern such as {"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.


  2. For anyone reading this thread and looking for additional Amazon EventBridge examples, there is a detailed Java V2 example that performs these tasks:

    1. Creates an AWS Identity and Access Management (IAM) role to use with Amazon EventBridge.
    2. Amazon Simple Storage Service (Amazon S3) bucket with EventBridge events enabled.
    3. Creates a rule that triggers when an object is uploaded to Amazon S3.
    4. Lists rules on the event bus.
    5. Creates a new Amazon Simple Notification Service (Amazon SNS) topic and lets the user subscribe to it.
    6. Adds a target to the rule that sends an email to the specified topic.
    7. Creates an EventBridge event that sends an email when an Amazon S3 object is created.
    8. Lists Targets.
    9. Lists the rules for the same target.
    10. Triggers the rule by uploading a file to the Amazon S3 bucket.
    11. Disables a specific rule.
    12. Checks and print the state of the rule.
    13. Adds a transform to the rule to change the text of the email.
    14. Enables a specific rule.
    15. Triggers the updated rule by uploading a file to the Amazon S3 bucket.
    16. Updates the rule to be a custom rule pattern.
    17. Sending an event to trigger the rule.
    18. Cleans up resources.

    See this example in the AWS Code Library:

    Get started with EventBridge rules and targets using an AWS SDK

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search