Skip to content

Instantly share code, notes, and snippets.

@atheiman
Created October 22, 2019 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save atheiman/c941311bcc93a1711b42cf772dc2bf01 to your computer and use it in GitHub Desktop.
Save atheiman/c941311bcc93a1711b42cf772dc2bf01 to your computer and use it in GitHub Desktop.
ec2 user_data snippets
# get instance attrs
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
PRIVATE_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
# get asg name
ASG_NAME=$(aws autoscaling describe-auto-scaling-instances --region us-east-1 --instance-ids $INSTANCE_ID --query 'AutoScalingInstances[0].AutoScalingGroupName' --output text)
# get tags
aws ec2 describe-tags --region us-east-1 --filters "Name=resource-id,Values=${INSTANCE_ID}"
# append to file
cat <<EOF >> file.txt
my ip is:
$PRIVATE_IP
end
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment