Fetching CloudWatch metrics using the AWS Java SDK?


I’m trying to fetch CPU stats from an EC2 instance using the CloudWatch API:


I have the following code but its returning an empty result, even though the instance Id, and AWS access and secret keys are correct.

I can see the CPU util for the instance on the CloudWatch UI, but can’t seem to get it below?

I’m using version 1.9.0 of the AWS SDK.

Any help much appreciated.


I was missing the endpoint setting on the client. Working now.

Changed this:

to this:

Leave a Reply