On terminal
#curl -s http://169.254.169.254/latest/meta-data/instance-id
gives the instance id, 169.254.169.254 is a special AWS internal IP address used to access the Instance Metadata Service (IMDS) from within an EC2 instance.