我正在编写Java代码来检索EC2实例的以下信息?但是不确定使用正确的AWS API来获取这些信息。
答案 0 :(得分:1)
您可以从实例元数据中获取该信息,如https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
中所述请注意,这是本地为每个实例托管的HTTP服务,位于169.254.169.254,您可以使用java http客户端或直接访问它,例如:
$ curl http://169.254.169.254/latest/meta-data/instance-id
i-024a0de14f70ab64f
这些是通过实例类型定义的:
$ curl http://169.254.169.254/latest/meta-data/instance-type
t3.2xlarge
这是由图像定义的,可以从describe-images api中获取详细信息
$ aws ec2 describe-images \
--image-ids $(curl -s http://169.254.169.254/latest/meta-data/ami-id)
{
"Images": [
{
"VirtualizationType": "hvm",
"Description": "Cloud9 Cloud9Default AMI",
"Hypervisor": "xen",
"EnaSupport": true,
"SriovNetSupport": "simple",
"ImageId": "ami-07606bae9eee7051c",
"State": "available",
"BlockDeviceMappings": [
{
"DeviceName": "/dev/xvda",
"Ebs": {
"SnapshotId": "snap-0ee3e3de47cfb2ce4",
"DeleteOnTermination": true,
"VolumeType": "gp2",
"VolumeSize": 8,
"Encrypted": false
}
}
],
"Architecture": "x86_64",
"ImageLocation": "751997845865/Cloud9Default-2019-02-18T10-14",
"RootDeviceType": "ebs",
"OwnerId": "751997845865",
"RootDeviceName": "/dev/xvda",
"CreationDate": "2019-02-18T11:02:13.000Z",
"Public": true,
"ImageType": "machine",
"Name": "Cloud9Default-2019-02-18T10-14"
}
]
}