Is there any way to get the platform and OS from the instances

删除回忆录丶 提交于 2019-12-02 07:32:33

问题


I am trying get some information from my AWS EC2 instances. I will like to know if there is a way to pull information like:

| Platform  | Version        |
|-----------|---------------:|
| CentOS    |  6.0 or 7.0    |
| Ubuntu    | 10.04 or 12.04 |
| Windows   |                |

I will like to know if this is possible using the SDK. I tried with Python SDK Boto3 but no results.


回答1:


It is not possible with SDK or CLI unless you have stored that information as tags. AWS SDK and CLI can help you get information that are available at the hypervisor level. But what you are asking is available inside the VM not at hypervisor.

While the following CLI command can help you a bit, but there is no guarantee you will get the platform information for all instances.

aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Platform]' --output text

i-07843115f653771c8 windows
i-e34364c87d4cebd12 None
i-0493b6a67b31df018 None



回答2:


We can obtain the platform as already answered by @helloV, but there is no means to get the OS directly. But we can use the image id to determine the OS name using some string operations. Using the below command we can obtain the image names, in which we have the operating system names to some extent.

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

The output of the command is as follows:
[
    "RHEL-7.6_HVM_GA-20190128-x86_64-0-Hourly2-GP2",
    "CentOS_7.5_Private",
    "amzn2-ami-hvm-2.0.20191024.3-x86_64-gp2",
    "amzn-ami-hvm-2018.03.0.20190826-x86_64-gp2",
    "Windows_Server-2016-English-Full-Base-2019.11.13",
    "Windows_Server-2019-English-Full-Base-2019.10.09"
]

Further, if you have an SSM agent installed on you instance,you can run the below command to get the exact Operating System Name.

aws ssm describe-instance-information --query 'InstanceInformationList[*].[InstanceId,PlatformType,PlatformName]' --output text | sort

The output of this command is as follows:
i-xxxxxxxxxxxx     Linux   Amazon Linux AMI
i-xxxxxxxxxxxx     Linux   CentOS Linux
i-xxxxxxxxxxxx     Linux   Amazon Linux
i-xxxxxxxxxxxx     Windows Microsoft Windows Server 2016 Datacenter

Hope this helps!



来源:https://stackoverflow.com/questions/41172415/is-there-any-way-to-get-the-platform-and-os-from-the-instances

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