title: Getting latest data from AWS custom Cloudwatch in Java
body: <p>I have a custom metric in AWS cloudwatch and i am putting data into it through AWS java API. </p>
  
  <pre><code>for(int i =0;i&lt;collection.size();i++){
          String[] cell = collection.get(i).split("\\|\\|");
          List&lt;Dimension&gt; dimensions = new ArrayList&lt;&gt;();
          dimensions.add(new Dimension().withName(dimension[0]).withValue(cell[0]));
          dimensions.add(new Dimension().withName(dimension[1]).withValue(cell[1]));
          MetricDatum datum = new MetricDatum().withMetricName(metricName)
                                               .withUnit(StandardUnit.None)
                                               .withValue(Double.valueOf(cell[2]))
                                               .withDimensions(dimensions);
          PutMetricDataRequest request = new PutMetricDataRequest().withNamespace(namespace+"_"+cell[3]).withMetricData(datum);
          String response = String.valueOf(cw.putMetricData(request));
  
          GetMetricDataRequest res = new GetMetricDataRequest().withMetricDataQueries();
          //cw.getMetricData();
          com.amazonaws.services.cloudwatch.model.Metric m = new com.amazonaws.services.cloudwatch.model.Metric();
          m.setMetricName(metricName);
          m.setDimensions(dimensions);
          m.setNamespace(namespace);
          MetricStat ms = new MetricStat().withMetric(m);
          MetricDataQuery metricDataQuery = new MetricDataQuery();
          metricDataQuery.withMetricStat(ms);
          metricDataQuery.withId("m1");
          List&lt;MetricDataQuery&gt; mqList = new ArrayList&lt;MetricDataQuery&gt;();
          mqList.add(metricDataQuery);
          res.withMetricDataQueries(mqList);
          GetMetricDataResult result1=  cw.getMetricData(res);
  
  
      }
  </code></pre>
  
  <p>Now i want to be able to fetch the latest data entered for a particular namespace, metric name and dimention combination through Java API. I am not able to find appropriate documenation from AWS regarding the same. Can anyone please help me?</p>