//snippet-sourcedescription:[GetLogEvents.java demonstrates how to get log events from CloudWatch in a specified region. ]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[cloudwatch]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[2019-06-20]
//snippet-sourceauthor:[ceruleancee]
// snippet-start:[cloudwatch.java2.get_logs.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.get_logs.import]
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsClient;
import software.amazon.awssdk.services.cloudwatchlogs.model.GetLogEventsRequest;
// snippet-end:[cloudwatch.java2.get_logs.import]

/**
 * Gets logs events from CloudWatch
 */
public class GetLogEvents {

    public static void main(String[] args) {

        final String usage =
                "To run this example, supply a regionName (e.g. us-east-1), logGroupName, and streamName as command line arguments\n" +
                        "Ex: GetLogEvents <regionName> <logGroupName> <streamName>\n";

        if (args.length != 3) {
            System.out.print(usage);
            System.exit(1);
        }

        // snippet-start:[cloudwatch.java2.get_logs.main]
        String region = args[0];
        String logStreamName = args[1];
        String logGroupName = args[2];

        // Create a CloudWatchLogClient
        CloudWatchLogsClient cloudWatchLogsClient = CloudWatchLogsClient.builder()
                .region(Region.of(region))
                .build();

        // Designate logGroupName and logStream you want to get logs from
        // Assume only one stream name exist, this is not always the case
        GetLogEventsRequest getLogEventsRequest = GetLogEventsRequest.builder()
                .logGroupName(logGroupName)
                .logStreamName(logStreamName)
                .startFromHead(true)
                .build();

        int logLimit = cloudWatchLogsClient.getLogEvents(getLogEventsRequest).events().size();
        for (int c = 0; c < logLimit; c++) {
            // Prints the messages to the console
            System.out.println(cloudWatchLogsClient.getLogEvents(getLogEventsRequest).events().get(c).message());
        }
        System.out.println("Successfully got CloudWatch log events!");
        // snippet-end:[cloudwatch.java2.get_logs.main]
    }
}
// snippet-end:[cloudwatch.java2.get_logs.complete]
@@ -278,16 +278,16 @@
 te:%5B
-2019-06-
+12/12/20
 20%5D%0A
@@ -314,19 +314,16 @@
 or:%5B
-ceruleancee
+scmacdon
 %5D%0A//
@@ -1078,19 +1078,50 @@
 sdk.
-regions.Reg
+services.cloudwatch.model.CloudWatchExcept
 ion;
@@ -1527,37 +1527,8 @@
 ly a
- regionName (e.g. us-east-1),
  log
@@ -1629,21 +1629,8 @@
 ents
- %3CregionName%3E
  %3Clo
@@ -1690,9 +1690,9 @@
  != 
-3
+2
 ) %7B%0A
@@ -1829,41 +1829,8 @@
 in%5D%0A
-        String region = args%5B0%5D;%0A
     
@@ -1861,17 +1861,17 @@
  = args%5B
-1
+0
 %5D;%0A     
@@ -1900,17 +1900,17 @@
  = args%5B
-2
+1
 %5D;%0A%0A    
@@ -2047,63 +2047,38 @@
     
- .region(Region.of(region))%0A                .build();%0A%0A
+.build();%0A%0A        try %7B%0A%0A    
     
@@ -2155,16 +2155,20 @@
         
+    
 // Assum
@@ -2225,16 +2225,20 @@
 he case%0A
+    
         
@@ -2471,16 +2471,20 @@
         
+    
 int logL
@@ -2570,16 +2570,20 @@
         
+   
+ 
 for (int
@@ -2607,24 +2607,28 @@
 mit; c++) %7B%0A
+    
             
@@ -2669,32 +2669,36 @@
 ole%0A            
+  
+  
 System.out.print
@@ -2783,16 +2783,168 @@
 age());%0A
+            %7D%0A        %7D catch (CloudWatchException e) %7B%0A            System.err.println(e.awsErrorDetails().errorMessage());%0A            System.exit(1);%0A
         
@@ -2937,32 +2937,33 @@
 t(1);%0A        %7D%0A
+%0A
         System.o
@@ -3112,28 +3112,29 @@
 tch.java2.get_logs.complete%5D
+%0A

Update GetLogEvents.java