I need to get this info ("Amazon Linux" line) via aws-cli or aws-sdk.
I've tried:
aws ec2 describe-images --image-id ami-0b898040803850657 --region us-east-1 --output json
But it doesn't give this kind of info in a straightforward way:
{
"Images": [
{
"Architecture": "x86_64",
"CreationDate": "2019-06-19T21:59:15.000Z",
"ImageId": "ami-0b898040803850657",
"ImageLocation": "amazon/amzn2-ami-hvm-2.0.20190618-x86_64-gp2",
"ImageType": "machine",
"Public": true,
"OwnerId": "137112412989",
"State": "available",
"BlockDeviceMappings": [
{
"DeviceName": "/dev/xvda",
"Ebs": {
"Encrypted": false,
"DeleteOnTermination": true,
"SnapshotId": "snap-08091107f3acb12b2",
"VolumeSize": 8,
"VolumeType": "gp2"
}
}
],
"Description": "Amazon Linux 2 AMI 2.0.20190618 x86_64 HVM gp2",
"EnaSupport": true,
"Hypervisor": "xen",
"ImageOwnerAlias": "amazon",
"Name": "amzn2-ami-hvm-2.0.20190618-x86_64-gp2",
"RootDeviceName": "/dev/xvda",
"RootDeviceType": "ebs",
"SriovNetSupport": "simple",
"VirtualizationType": "hvm"
}
]
}
Sure it is possible to parse "Description" field but there is no guarantee that the OS name is in the description.
So what is the correct way to get the OS of an AMI? Also note that I need to differentiate between RHEL, SUSE, Linux and Windows. I need the info about OS to lookup the pricing for my instances (programmatically). If someone knows the easier way then please feel free to share.