简体   繁体   中英

Get current InstanceId in AWS Java SDK

I am using the AWS CloudWatch SDK to record metrics from a program running inside EC2 instance. I would like to report back the InstanceId as a dimension for these metrics. How do I find out the EC2 InstanceId from a Java program running inside the instance?

Use EC2MetadataUtils .

import software.amazon.awssdk.regions.internal.util.EC2MetadataUtils;

String instanceId = EC2MetadataUtils.getInstanceId();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM