//snippet-sourcedescription:[PutRule.java demonstrates how to creates a CloudWatch event-routing rule.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[cloudwatch]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[]
//snippet-sourceauthor:[soo-aws]
// snippet-start:[cloudwatch.java2.put_rule.complete]
/*
 * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package com.example.cloudwatch;
// snippet-start:[cloudwatch.java2.put_rule.import]
import software.amazon.awssdk.services.cloudwatchevents.CloudWatchEventsClient;
import software.amazon.awssdk.services.cloudwatchevents.model.PutRuleRequest;
import software.amazon.awssdk.services.cloudwatchevents.model.PutRuleResponse;
import software.amazon.awssdk.services.cloudwatchevents.model.RuleState;
// snippet-end:[cloudwatch.java2.put_rule.import]

/**
 * Creates a CloudWatch event-routing rule
 */
public class PutRule {

    public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply a rule name and role arn\n" +
            "Ex: PutRule <rule-name> <role-arn>\n";

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

        String rule_name = args[0];
        String role_arn = args[1];

        // snippet-start:[cloudwatch.java2.put_rule.main]
        CloudWatchEventsClient cwe =
        		CloudWatchEventsClient.builder().build();

        PutRuleRequest request = PutRuleRequest.builder()
            .name(rule_name)
            .roleArn(role_arn)
            .scheduleExpression("rate(5 minutes)")
            .state(RuleState.ENABLED)
            .build();

        PutRuleResponse response = cwe.putRule(request);
        // snippet-end:[cloudwatch.java2.put_rule.main]

        System.out.printf(
            "Successfully created CloudWatch events rule %s with arn %s",
            rule_name, response.ruleArn());
    }
}
// snippet-end:[cloudwatch.java2.put_rule.complete]
@@ -260,16 +260,26 @@
 cedate:%5B
+13/02/2020
 %5D%0D%0A//sni
@@ -302,69 +302,18 @@
 r:%5Bs
-oo-aws%5D%0A// snippet-start:%5Bcloudwatch.java2.put_rule.complete%5D
+cmacdon%5D%0D%0A
 %0D%0A/*
@@ -338,10 +338,10 @@
 0-20
-19
+20
  Ama
@@ -907,16 +907,17 @@
 se.%0D%0A */
+%0D
 %0Apackage
@@ -986,23 +986,156 @@
 ut_rule.
-import%5D
+complete%5D%0D%0A// snippet-start:%5Bcloudwatch.java2.put_rule.import%5D%0D%0Aimport software.amazon.awssdk.services.cloudwatch.model.CloudWatchException;
 %0D%0Aimport
@@ -1547,16 +1547,17 @@
 ule%0D%0A */
+%0D
 %0Apublic 
@@ -1665,16 +1665,20 @@
         
+    
 %22To run 
@@ -1729,16 +1729,28 @@
 n%5Cn%22 +%0D%0A
+            
         
@@ -1930,18 +1930,17 @@
 ing rule
-_n
+N
 ame = ar
@@ -1966,18 +1966,17 @@
 ing role
-_a
+A
 rn = arg
@@ -1980,24 +1980,89 @@
 args%5B1%5D;%0D%0A%0D%0A
+        PutRuleResponse response = null;%0D%0A%0D%0A        try %7B%0D%0A%0D%0A    
         // s
@@ -2116,16 +2116,20 @@
         
+    
 CloudWat
@@ -2162,10 +2162,16 @@
     
+  
-%09%09
+      
 Clou
@@ -2203,32 +2203,36 @@
 r().build();%0D%0A%0D%0A
+    
         PutRuleR
@@ -2286,16 +2286,20 @@
         
+    
 .name(ru
@@ -2304,16 +2304,19 @@
 rule
-_n
+N
 ame)%0D%0A
+    
     
@@ -2336,19 +2336,57 @@
 Arn(
-role_arn)%0D%0A
+%22arn:aws:iam::335446330391:role/testRole1%22)%0D%0A    
     
@@ -2445,16 +2445,20 @@
         
+    
 .state(R
@@ -2488,16 +2488,20 @@
         
+    
 .build()
@@ -2509,39 +2509,27 @@
 %0D%0A%0D%0A        
-PutRuleResponse
+   
  response = 
@@ -2606,24 +2606,188 @@
 le.main%5D%0D%0A%0D%0A
+        %7D catch (%0D%0A            CloudWatchException e) %7B%0D%0A            System.err.println(e.awsErrorDetails().errorMessage());%0D%0A            System.exit(1);%0D%0A    %7D%0D%0A%0D%0A
         Syst
@@ -2802,16 +2802,20 @@
 rintf(%0D%0A
+    
         
@@ -2897,17 +2897,19 @@
     
+   
-rule_name
+ roleArn
 , re
@@ -2969,28 +2969,30 @@
 tch.java2.put_rule.complete%5D
+%0D%0A

Update PutRule.java