//snippet-sourcedescription:[GetMetricData.java demonstrates how to get metric data.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[cloudwatch]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[03/02/2020]
//snippet-sourceauthor:[scmacdon]
/*
 * Copyright 2010-2020 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.
 */
// snippet-start:[cloudwatch.java2.put_metric_data.complete]
// snippet-start:[cloudwatch.java2.put_metric_data.import]
package com.example.cloudwatch;
import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
import software.amazon.awssdk.services.cloudwatch.model.GetMetricDataResponse;
import software.amazon.awssdk.services.cloudwatch.model.Metric;
import software.amazon.awssdk.services.cloudwatch.model.MetricStat;
import software.amazon.awssdk.services.cloudwatch.model.MetricDataQuery;
import software.amazon.awssdk.services.cloudwatch.model.GetMetricDataRequest;
import software.amazon.awssdk.services.cloudwatch.model.MetricDataResult;
import software.amazon.awssdk.services.cloudwatch.model.CloudWatchException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

// snippet-end:[cloudwatch.java2.put_metric_data.import]
/**
 * Puts a sample metric data point
 */
public class GetMetricData {


    public static void main(String[] args) {
        // snippet-start:[cloudwatch.java2.put_metric_alarm.main]
        CloudWatchClient cw = CloudWatchClient.builder()
                .build();


        try {

            // Set the date
            Instant start = Instant.ofEpochMilli(new Date().getTime());
            start = Instant.parse("2019-10-23T10:12:35Z");

            Instant endDate = Instant.now();

            Metric met = Metric.builder()
                    .metricName("DiskReadBytes")
                    .namespace("AWS/EC2")
                     .build();

            MetricStat metStat = MetricStat.builder()
                    .stat("Minimum")
                    .period(60)
                    .metric(met)
                    .build();

            MetricDataQuery dataQUery = MetricDataQuery.builder()
                    .metricStat(metStat)
                    .id("foo2")
                    .returnData(true)
                    .build();

            List<MetricDataQuery> dq = new ArrayList();
            dq.add(dataQUery);

            GetMetricDataRequest getMetReq = GetMetricDataRequest.builder()
                .maxDatapoints(100)
                .startTime(start)
                .endTime(endDate)
                .metricDataQueries(dq)
                .build();

            GetMetricDataResponse response = cw.getMetricData(getMetReq);

            List<MetricDataResult> data = response.metricDataResults();

            for (int i = 0; i < data.size(); i++) {

                MetricDataResult item = (MetricDataResult) data.get(i);
             System.out.println("The label is "+item.label());
                System.out.println("The status code is "+item.statusCode().toString());
            }

       } catch (CloudWatchException e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
        // snippet-end:[cloudwatch.java2.put_metric_alarm.main]
    }
}
// snippet-end:[cloudwatch.java2.put_metric_data.complete]

@@ -22,18 +22,18 @@
 iption:%5B
-Ge
+Pu
 tMetricD
@@ -167,22 +167,29 @@
 ervice:%5B
-c
+Amazon C
 loud
-w
+W
 atch%5D%0A//
@@ -310,18 +310,8 @@
 ght 
-2010-2020 
 Amaz
@@ -869,68 +869,8 @@
  */%0A
-// snippet-start:%5Bcloudwatch.java2.put_metric_data.complete%5D
 %0A// 
@@ -957,16 +957,62 @@
 dwatch;%0A
+import software.amazon.awssdk.regions.Region;%0A
 import s
@@ -1684,17 +1684,16 @@
 l.List;%0A
-%0A
 // snipp
@@ -1741,16 +1741,17 @@
 import%5D%0A
+%0A
 /**%0A * P
@@ -1815,17 +1815,16 @@
 Data %7B%0A%0A
-%0A
     publ
@@ -1860,24 +1860,25 @@
 args) %7B%0A
+%0A
         
 // snipp
@@ -1873,65 +1873,41 @@
     
-// snippet-start:%5Bcloudwatch.java2.put_metric_alarm.main%5D
+Region region = Region.US_EAST_1;
 %0A   
@@ -1977,25 +1977,209 @@
        .
-build();%0A
+region(region)%0A                .build();%0A%0A        getMetData(cw) ;%0A    %7D%0A%0A    // snippet-start:%5Bcloudwatch.java2.put_metric_alarm.main%5D%0A    public static void getMetData( CloudWatchClient cw) %7B
 %0A%0A      
@@ -2186,17 +2186,16 @@
   try %7B%0A
-%0A
         
@@ -3564,32 +3564,35 @@
 );%0A             
+   
 System.out.print
@@ -3735,16 +3735,17 @@
 %0A       
+ 
 %7D catch 
@@ -3952,63 +3952,4 @@
 %7D%0A%7D%0A
-// snippet-end:%5Bcloudwatch.java2.put_metric_data.complete%5D%0A

Update GetMetricData.java