How to find OS of an EC2 instance using AWS CLI

后端 未结 4 831
鱼传尺愫
鱼传尺愫 2020-12-10 07:49

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 n

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 08:29

    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.

提交回复
热议问题