I am currently trying to create a Java application that can call and reference the Amazon AWS API through the AWS Java SDK. I have been able to make calls directly to services like S3 and EC2 but when I try to pull data from Cloudwatch, I am unable to get any datapoints.
I have tried adjusting different variables (Dimensions, adjusting the time variables) and I have tried to pull the data through the CLI. When I request the data through the CLI, I AM able to get datapoints but the Java app does not get the same data. Here is my CLI code:
aws cloudwatch get-metric-statistics --metric-name BucketSizeBytes --namespace "AWS/S3" --start-time 2019-06-21T00:00:00Z --end-time 2019-06-22T00:00:00Z --period 3600 --statistics Average --unit Bytes --output json --region us-east-1 --dimensions Name=BucketName,Value=XXXXX Name=StorageType,Value=StandardStorage
Here is what I am using on the Java side. The variable namespace is equal to the string "AWS/S3" and the variable region is set to Region.US_EAST_1
Setting up CloudWatch Client
private CloudWatchClient cwClient = CloudWatchClient.builder().region(region).build();
Calling the Data
public S3 individualS3BucketSize(S3 s3) {
Instant now = Instant.now();
Dimension dimensions = Dimension.builder().name("BucketName").value("XXXXX").name("StorageType").value("StandardStorage").build();
GetMetricStatisticsRequest request = GetMetricStatisticsRequest.builder().namespace(namespace).metricName("BucketSizeBytes")
.statistics(Statistic.AVERAGE)
.startTime(now.minus(Duration.ofDays(1))).endTime(now).period(3600)
.dimensions(dimensions)
.build();
GetMetricStatisticsResponse response;
response = cwClient.getMetricStatistics(request);
System.out.println(response.toString());
}
When the method is called and the print method is run, I get:
GetMetricStatisticsResponse(Label=BucketSizeBytes, Datapoints=[])
Any thoughts as to why it is coming back blank in the Java app but not the CLI?