How to find OS of an EC2 instance using AWS CLI

匿名 (未验证) 提交于 2019-12-03 02:26:02

问题:

How can you find out the OS running on an EC2 instance using AWS CLI.

The ec2 describe-instance command spits out a lot of information , but there is nothing indicating the OS .

I also tried ec2 describe-images on a specific image. Again, there doesn't seem to be any indication of OS.

Help..?

回答1:

Here's a quick way to list the Platform field, which at least distinguishes between Windows and Linux:

aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Platform]' --output text i-78b4ef47  windows i-b8ae3386  windows i-9d3611a2  None i-1c57c651  windows i-a241ec91  None i-7d26b630  None 


回答2:

Try this command:

aws ec2 describe-images --image-ids $(aws ec2 describe-instances --instance-ids i-xxxxxxxxxxxxx --query 'Reservations[0].Instances[0].ImageId' --output text) --query 'Images[0].Name' 

$() part gets the ImageId using InstanceId.



回答3:

You can't query the specific OS of the instance from the AWS cli but you can query the AMI that the instance is based off of. Also, you can't get an 'OS' attribute but you can get the Description or Name of the AMI, so if you create your AMIs with a meaningful description you can make it work.

$ aws ec2 describe-images --image-ids "ami-xxxxxxxx" {     "Images": [         {             "VirtualizationType": "paravirtual",              "Name": "amazon-linux-20130509",              "Tags": [                 {                     "Value": "amazon-linux-20130509",                      "Key": "Name"                 }             ],              "Hypervisor": "xen",              "ImageId": "ami-xxxxxxxx",              "RootDeviceType": "ebs",              "State": "available",              "BlockDeviceMappings": [                 {                     "DeviceName": "/dev/sda1",                      "Ebs": {                         "DeleteOnTermination": true,                          "SnapshotId": "snap-xxxxxxxx",                          "VolumeSize": 100,                          "VolumeType": "standard"                     }                 }             ],              "Architecture": "x86_64",              "ImageLocation": "123456789012/amazon-linux-20130509",              "KernelId": "aki-fc37bacc",              "OwnerId": "123456789012",              "RootDeviceName": "/dev/sda1",              "Public": false,              "ImageType": "machine",              "Description": "Amazon Linux"         }     ] } 

If you want to get more detailed you can always write your own script to ssh into the machines and run cat /etc/issue in each one of them.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!