Skip to content

Instantly share code, notes, and snippets.

@OneCricketeer
Created March 10, 2021 16:46
Show Gist options
  • Save OneCricketeer/4dcbb7bf9902b5ef504c49f0781a4d81 to your computer and use it in GitHub Desktop.
Save OneCricketeer/4dcbb7bf9902b5ef504c49f0781a4d81 to your computer and use it in GitHub Desktop.
Get AWS metadata
IP_ADDRESS=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
HOSTNAME=$(hostname -f)
HOSTNAME_SHORT=$(hostname -s)
AWS_DNS=$(cat /etc/resolv.conf |grep -i nameserver|head -n1|cut -d ' ' -f2)
DOMAIN_NAME=$(curl -s http://169.254.169.254/latest/meta-data/local-hostname | cut -d "." -f 2-)
REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')
AZ=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep availabilityZone | awk -F\" '{print $4}')
MAC_ETH0=`curl -s http://169.254.169.254/latest/meta-data/mac`
VPC_ID=`curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC_ETH0/vpc-id`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment