Created
March 22, 2017 16:19
-
-
Save salekseev/c8f5d0130ac180fd404343aa49654338 to your computer and use it in GitHub Desktop.
Script to find private IP addresses of all EC2 instances participating in the CloudFormation stack
This file contains hidden or 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
#!/bin/bash | |
command -v aws >/dev/null 2>&1 || { echo >&2 "I require awscli but it's not installed. Aborting."; exit 1; } | |
command -v curl >/dev/null 2>&1 || { echo >&2 "I require curl but it's not installed. Aborting."; exit 1; } | |
# Find local instance_id | |
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
# Find cloudformation stack-id | |
STACK_ID=$(aws ec2 describe-instances --output text --instance-ids $INSTANCE_ID | grep -e 'TAGS\saws:cloudformation:stack-id' | awk '{print $3}') | |
aws ec2 describe-instances --output text --filters "Name=tag:aws:cloudformation:stack-id,Values=${STACK_ID}" | grep PRIVATEIPADDRESSES | awk '{print $4}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run this script from one of the EC2 instances participating in the stack to discover other stack members.