Created
October 22, 2019 01:44
-
-
Save atheiman/c941311bcc93a1711b42cf772dc2bf01 to your computer and use it in GitHub Desktop.
ec2 user_data snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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