@@ -0,0 +1,2930 @@
+//snippet-sourcedescription:%5BCreateRule.java demonstrates how to create an Amazon EventBridge rule.%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._create_rule.import%5D%0Aimport software.amazon.awssdk.regions.Region;%0Aimport software.amazon.awssdk.services.eventbridge.EventBridgeClient;%0Aimport software.amazon.awssdk.services.eventbridge.model.PutRuleRequest;%0Aimport software.amazon.awssdk.services.eventbridge.model.PutRuleResponse;%0Aimport software.amazon.awssdk.services.eventbridge.model.EventBridgeException;%0A// snippet-end:%5Beventbridge.java2._create_rule.import%5D%0A%0Apublic class CreateRule %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        final String USAGE = %22%5Cn%22 +%0A                %22Usage:%5Cn%22 +%0A                %22    DescribeRule %3CruleName%3E %5Cn%5Cn%22 +%0A                %22Where:%5Cn%22 +%0A                %22    ruleName - the rule name to describe %5Cn%22;%0A%0A        if (args.length %3C 1) %7B%0A            System.out.println(USAGE);%0A            System.exit(1);%0A        %7D%0A%0A        String ruleName = args%5B0%5D;%0A%0A        Region region = Region.US_WEST_2;%0A        EventBridgeClient eventBrClient = EventBridgeClient.builder()%0A                .region(region)%0A                .build();%0A%0A        createEBRule(eventBrClient, ruleName);%0A    %7D%0A%0A    // snippet-start:%5Beventbridge.java2._create_rule.main%5D%0A    public static void createEBRule(EventBridgeClient eventBrClient, String ruleName) %7B%0A%0A    try %7B%0A%0A        PutRuleRequest ruleRequest = PutRuleRequest.builder()%0A                 .name(ruleName)%0A                .eventBusName(%22default%22)%0A                .eventPattern(%22%7B%5C%22source%5C%22:%5B%5C%22aws.s3%5C%22%5D,%5C%22detail-type%5C%22:%5B%5C%22AWS API Call via CloudTrail%5C%22%5D,%5C%22detail%5C%22:%7B%5C%22eventSource%5C%22:%5B%5C%22s3.amazonaws.com%5C%22%5D,%5C%22eventName%5C%22:%5B%5C%22DeleteBucket%5C%22%5D%7D%7D%22)%0A                .description(%22A test rule created by the Java API%22)%0A                .build();%0A%0A        PutRuleResponse ruleResponse = eventBrClient.putRule(ruleRequest);%0A        System.out.println(%22The ARN of the new rule is %22+ ruleResponse.ruleArn());%0A%0A    %7D catch (EventBridgeException e) %7B%0A%0A        System.err.println(e.awsErrorDetails().errorMessage());%0A        System.exit(1);%0A    %7D%0A    // snippet-end:%5Beventbridge.java2._create_rule.main%5D%0A    %7D%0A%7D%0A

Create CreateRule.java