//snippet-sourcedescription:[PutMetricData.java demonstrates how to put a sample metric data point for a metric defined for a CloudWatch alarm.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[cloudwatch]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[]
//snippet-sourceauthor:[soo-aws]
/*
 * 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.
 */
// 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.Dimension;
import software.amazon.awssdk.services.cloudwatch.model.MetricDatum;
import software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest;
import software.amazon.awssdk.services.cloudwatch.model.PutMetricDataResponse;
import software.amazon.awssdk.services.cloudwatch.model.StandardUnit;

// snippet-end:[cloudwatch.java2.put_metric_data.import]
/**
 * Puts a sample metric data point
 */
public class PutMetricData {
    public static void main(String[] args) {
        
        
        final String USAGE =
            "To run this example, supply a data point:\n" +
            "Ex: PutMetricData <data_point>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }
        // snippet-start:[cloudwatch.java2.put_metric_data.main]
        Double data_point = Double.parseDouble(args[0]);

        CloudWatchClient cw =
        		CloudWatchClient.builder().build();

        Dimension dimension = Dimension.builder()
            .name("UNIQUE_PAGES")
            .value("URLS").build();

        MetricDatum datum = MetricDatum.builder()
            .metricName("PAGES_VISITED")
            .unit(StandardUnit.NONE)
            .value(data_point)
            .dimensions(dimension).build();

        PutMetricDataRequest request = PutMetricDataRequest.builder()
            .namespace("SITE/TRAFFIC")
            .metricData(datum).build();

        PutMetricDataResponse response = cw.putMetricData(request);

        System.out.printf("Successfully put data point %f", data_point);
        // snippet-end:[cloudwatch.java2.put_metric_data.main]
    }
}
// snippet-end:[cloudwatch.java2.put_metric_data.complete]
@@ -301,16 +301,26 @@
 cedate:%5B
+13/02/2020
 %5D%0D%0A//sni
@@ -343,14 +343,15 @@
 r:%5Bs
-oo-aws
+cmacdon
 %5D%0D%0A/
@@ -377,10 +377,10 @@
 0-20
-19
+20
  Ama
@@ -1310,16 +1310,87 @@
 Datum;%0D%0A
+import software.amazon.awssdk.services.cloudwatch.model.StandardUnit;%0D%0A
 import s
@@ -1596,31 +1596,36 @@
 h.model.
-StandardUnit;%0D%0A
+CloudWatchException;
 %0D%0A// sni
@@ -1798,34 +1798,16 @@
 rgs) %7B%0D%0A
-        %0D%0A        
 %0D%0A      
@@ -1842,16 +1842,20 @@
         
+    
 %22To run 
@@ -1895,16 +1895,28 @@
 :%5Cn%22 +%0D%0A
+            
         
@@ -2152,26 +2152,25 @@
  Double data
-_p
+P
 oint = Doubl
@@ -2239,10 +2239,16 @@
     
-%09%09
+        
 Clou
@@ -2274,32 +2274,53 @@
 r().build();%0D%0A%0D%0A
+        try %7B%0D%0A%0D%0A    
         Dimensio
@@ -2346,32 +2346,36 @@
 sion.builder()%0D%0A
+    
             .nam
@@ -2401,24 +2401,28 @@
             
+    
 .value(%22URLS
@@ -2444,16 +2444,20 @@
         
+   
+ 
 MetricDa
@@ -2499,24 +2499,28 @@
             
+    
 .metricName(
@@ -2549,16 +2549,20 @@
         
+  
+  
 .unit(St
@@ -2587,24 +2587,28 @@
             
+    
 .value(data_
@@ -2610,17 +2610,20 @@
 data
-_p
+P
 oint)%0D%0A
+    
     
@@ -2665,32 +2665,36 @@
 d();%0D%0A%0D%0A        
+  
+  
 PutMetricDataReq
@@ -2748,24 +2748,28 @@
             
+    
 .namespace(%22
@@ -2792,24 +2792,28 @@
             
+ 
+   
 .metricData(
@@ -2823,32 +2823,36 @@
 um).build();%0D%0A%0D%0A
+    
         PutMetri
@@ -2902,24 +2902,176 @@
 equest);%0D%0A%0D%0A
+        %7D catch (CloudWatchException e) %7B%0D%0A            System.err.println(e.awsErrorDetails().errorMessage());%0D%0A            System.exit(1);%0D%0A        %7D%0D%0A
         Syst
@@ -3118,26 +3118,25 @@
 nt %25f%22, data
-_p
+P
 oint);%0D%0A    
@@ -3243,28 +3243,30 @@
 a2.put_metric_data.complete%5D
+%0D%0A

Update PutMetricData.java