Reputation: 11
I am writing Java code to retrieve below info of an EC2 instance? But not sure about the right AWS API to use to get these info.
Upvotes: 1
Views: 1661
Reputation: 13501
You can get that from the instance metadata, as described at https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
Note that this is an HTTP service hosted locally for each instance at 169.254.169.254, you can access with java http clients or directly, for example:
$ curl http://169.254.169.254/latest/meta-data/instance-id
i-024a0de14f70ab64f
These are defined by the instance-type:
$ curl http://169.254.169.254/latest/meta-data/instance-type
t3.2xlarge
This is defined by the image, and the details can be fetched from the 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"
}
]
}
Upvotes: 1