How to detect AWS EC2 architecture from inside?

Assuming we have instance running, what can we run on that instance to detect whether it's x86_64 or graviton-based/ARM?

I thought about curl -s http://169.254.169.254/latest/meta-data/... but found nothing useful in this case. Also, it's possible to detect using instance type (e.g. t4g.* vs t3.*) but I'd like to have more straightforward way.

Is there any?


Solution 1:

Quick and easy check: uname -m

Intel / AMD:

t3a.large:~ $ uname -m
x86_64

Graviton / ARM:

t4g.large:~ $ uname -m
aarch64

Display more details: lscpu

For example for AMD CPU:

t3a.large:~ $ lscpu
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   48 bits physical, 48 bits virtual
CPU(s):                          2
On-line CPU(s) list:             0,1
Thread(s) per core:              2
Core(s) per socket:              1
Socket(s):                       1
NUMA node(s):                    1
Vendor ID:                       AuthenticAMD
CPU family:                      23
Model name:                      AMD EPYC 7571
CPU MHz:                         2199.880
BogoMIPS:                        4399.76
Hypervisor vendor:               KVM
Virtualization type:             full
L1d cache:                       32 KiB
L1i cache:                       64 KiB
L2 cache:                        512 KiB
L3 cache:                        8 MiB
NUMA node0 CPU(s):               0,1
...

You can also display the output in JSON format for easier consumption in scripts (here for Graviton):

t4g.large:~ $ lscpu -J
{
   "lscpu": [
      {"field":"Architecture:", "data":"aarch64"},
      {"field":"CPU op-mode(s):", "data":"32-bit, 64-bit"},
      {"field":"Byte Order:", "data":"Little Endian"},
      {"field":"CPU(s):", "data":"2"},
      {"field":"On-line CPU(s) list:", "data":"0,1"},
      {"field":"Thread(s) per core:", "data":"1"},
      {"field":"Core(s) per socket:", "data":"2"},
      {"field":"Vendor ID:", "data":"ARM"},
      {"field":"Model name:", "data":"Neoverse-N1"},
      ...
   ]
}

Hope that helps :)