Display EC2 Instance ID on the Instance CLI

From Bonus Bits
Jump to: navigation, search

Purpose

This article gives the steps to display the EC2 Instance ID while logged into the system from command line.


Prerequisites

  • Instance ReadOnly EC2 profile access.


Query API

wget -q -O - http://instance-data/latest/meta-data/instance-id


Check Symlink

ls -alh /var/lib/cloud/

Example

drwxr-xr-x 2 root root 4096 Apr  6 19:53 data
drwxr-xr-x 2 root root 4096 Feb 19 21:25 handlers
lrwxrwxrwx 1 root root   35 Apr  6 19:26 instance -> /var/lib/cloud/instances/i-bd9ca77a
drwxr-xr-x 8 root root 4096 Apr  6 19:26 instances
drwxr-xr-x 6 root root 4096 Feb 19 21:25 scripts
drwxr-xr-x 2 root root 4096 Feb 19 21:25 seed
drwxr-xr-x 2 root root 4096 Feb 19 21:25 sem