In AWS there is a link-local address 169.254.169.254 which have metadata that EC2 instance can access. If you log in to an EC2 Instance, you can use curl or wget to get information about the instance from metadata endpoint:
curl http://169.254.169.254/latest/meta-data/
wget -q -O - http://169.254.169.254/latest/meta-data/
Exampleshttp://169.254.169.254/latest/meta-data/public-ipv4
Get local IP of instance:
curl http://169.254.169.254/latest/meta-data/local-ipv4
Get instance ID:
curl http://169.254.169.254/latest/meta-data/instance-id
Get instance type:
curl http://169.254.169.254/latest/meta-data/instance-type
Get AZ:
http://169.254.169.254/latest/meta-data/placement/availability-zone