Skip to content

Instantly share code, notes, and snippets.

@samof76
Last active January 7, 2019 09:35
Show Gist options
  • Save samof76/7415f0874a552316c58d57b033a65d62 to your computer and use it in GitHub Desktop.
Save samof76/7415f0874a552316c58d57b033a65d62 to your computer and use it in GitHub Desktop.
confd.sh
#!/bin/bash
# Get the instance id
instance_id=$(curl http://169.254.169.254/latest/meta-data/instance-id 2> /dev/null)
# Get the instance name
instance_hostname=$(aws ec2 describe-instances --instance-ids $instance_id | jq -r '.Reservations[0].Instances[0].Tags[] | select(.Key == "opsworks:instance") | .Value')
# Get the instance ip
instance_ipaddress=$(aws ec2 describe-instances --instance-ids $instance_id | jq -r '.Reservations[0].Instances[0].PrivateIpAddress')
uptime > /root/confd.txt
echo $instance_id >> /root/confd.txt
echo $instance_hostname >> /root/confd.txt
echo $instance_ipaddress >> /root/confd.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment