Identify EC2 Instances in a Mixed Computing Environment
If you are running computer resources on another cloud infrastructure, such as Azure or Google Cloud Platform, or if you use on-premises virtualization from VMware, Xen, or KVM, you may benefit from a simple method to determine whether a virtual machine is an EC2 instance. This topic describes two approaches to identifying an EC2 instance, one of them quick but potentially inaccurate, and the other more involved but also definitive.
Inspecting the Xen Domain UUID
The methods described in this section determine optimistically whether a Linux virtual machine is an EC2 instance by examining the Xen domain UUID. This approach looks for the presence of the characters "ec2" or "EC2" in the beginning octet of the UUID.
There is a small chance that a Xen instance not in EC2 could also include these characters.
You can discover the Xen UUID using the approaches below. For information about identifying Windows instances, see http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/identify_ec2_instances.html.
On a Linux VM, run the following command:Copy
$ cat /sys/hypervisor/uuid
This returns a UUID:Copy
In this example, the prepended "ec2" indicates that you are probably looking at an EC2 instance.
Alternatively, on HVM instances only, the Desktop Management Interface (DMI) contains the same UUID as the System Serial Number and the System UUID (capitalized):Copy
$ sudo dmidecode --string system-serial-number ec2e1916-9099-7caf-fd21-01234example $ sudo dmidecode --string system-uuid EC2E1916-9099-7CAF-FD21-01234EXAMPLE
Unlike the previous method, the DMI method requires superuser privileges. However, some older Linux kernels may not expose the UUID via
Inspecting the Instance Identity Document
For a definitive and cryptographically verified method of identifying an EC2 instance,
check the instance identity document, including its signature. These documents are
available on every EC2 instance at the local, non-routable address
http://169.254.169.254/latest/dynamic/instance-identity/. For more