获取AWS Java SDK中的当前InstanceId

huangapple go评论105阅读模式
英文:

Get current InstanceId in AWS Java SDK

问题

我正在使用AWS CloudWatch SDK从在EC2实例内运行的程序记录指标。我希望将InstanceId作为这些指标的一个维度进行报告。我应该如何从在实例内运行的Java程序中找到EC2 InstanceId?

英文:

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?

答案1

得分: 4

使用EC2MetadataUtils

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

String instanceId = EC2MetadataUtils.getInstanceId();
英文:

Use EC2MetadataUtils.

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

String instanceId = EC2MetadataUtils.getInstanceId();

huangapple
  • 本文由 发表于 2020年4月7日 18:05:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/61077499.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定