package com.example.eventbridge;

import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
import software.amazon.awssdk.services.eventbridge.model.EventBridgeException;
import software.amazon.awssdk.services.eventbridge.model.PutEventsRequest;
import software.amazon.awssdk.services.eventbridge.model.PutEventsRequestEntry;
import software.amazon.awssdk.services.eventbridge.model.PutEventsResponse;
import software.amazon.awssdk.services.eventbridge.model.PutEventsResultEntry;
import java.util.ArrayList;
import java.util.List;

public class PutEvents {

    public static void main(String[] args) {

        final String USAGE =
                "To run this example, supply a resource arn\n" +
                        "Ex: PutEvents <resource-arn>\n";

        if (args.length != 2) {
            System.out.println(USAGE);
            System.exit(1);
        }

        EventBridgeClient eventBrClient =
                EventBridgeClient.builder().build();


        String resourceArn = args[0];
        String resourceArn2 = args[1];

        putEBEvents(eventBrClient, resourceArn, resourceArn2);
    }

    public static void putEBEvents(EventBridgeClient eventBrClient, String resourceArn, String resourceArn2 ) {

        try {

            // Populate a List with the resource ARN values
            List<String> resources = new ArrayList<String>();
            resources.add(resourceArn);
            resources.add(resourceArn2);

            // Create a PutEventsRequestEntry object
            PutEventsRequestEntry reqEntry = PutEventsRequestEntry.builder()
                    .resources(resources)
                    .source("com.mycompany.myapp")
                    .detailType("myDetailType")
                    .detail("{ \"key1\": \"value1\", \"key2\": \"value2\" }")
                    .build();

            // Add the PutEventsRequestEntry to a list
            List<PutEventsRequestEntry> list = new ArrayList<PutEventsRequestEntry>();
            list.add(reqEntry);

            PutEventsRequest eventsRequest = PutEventsRequest.builder()
                    .entries(reqEntry)
                    .build();

            // Invoke the PutEvents method
            PutEventsResponse result = eventBrClient.putEvents(eventsRequest);

            for (PutEventsResultEntry resultEntry : result.entries()) {
                if (resultEntry.eventId() != null) {
                    System.out.println("Event Id: " + resultEntry.eventId());
                } else {
                    System.out.println("Injection failed with Error Code: " + resultEntry.errorCode());
                }
            }

        } catch (EventBridgeException e) {

            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
    }
}

@@ -1,37 +1,943 @@
-package com.example.eventbridge;%0A
+//snippet-sourcedescription:%5BPutEvents.java demonstrates how to send custom events to Amazon EventBridge.%5D%0A//snippet-keyword:%5BSDK for Java 2.0%5D%0A//snippet-keyword:%5BCode Sample%5D%0A//snippet-service:%5BAmazon EventBridge%5D%0A//snippet-sourcetype:%5Bfull-example%5D%0A//snippet-sourcedate:%5B7/22/2020%5D%0A//snippet-sourceauthor:%5Bscmacdon-aws%5D%0A%0A/*%0A   Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.%0A   This file is licensed under the Apache License, Version 2.0 (the %22License%22).%0A   You may not use this file except in compliance with the License. A copy of%0A   the License is located at%0A    http://aws.amazon.com/apache2.0/%0A   This file is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR%0A   CONDITIONS OF ANY KIND, either express or implied. See the License for the%0A   specific language governing permissions and limitations under the License.%0A*/%0A%0Apackage com.example.eventbridge;%0A%0A// snippet-start:%5Beventbridge.java2._put_event.import%5D
 %0Aimp
@@ -1442,16 +1442,69 @@
 il.List;
+%0A// snippet-end:%5Beventbridge.java2._put_event.import%5D
 %0A%0Apublic
@@ -1928,17 +1928,16 @@
 ild();%0A%0A
-%0A
         
@@ -2072,24 +2072,81 @@
 n2);%0A    %7D%0A%0A
+    // snippet-start:%5Beventbridge.java2._put_event.main%5D%0A
     public s
@@ -3796,20 +3796,79 @@
 ;%0A        %7D%0A
+        // snippet-end:%5Beventbridge.java2._put_event.main%5D%0A
     %7D%0A%7D%0A

Update PutEvents.java