Created
November 17, 2017 18:38
-
-
Save cdechery/6d7fb2b28e1d715e935de9a470da819b to your computer and use it in GitHub Desktop.
A simple shell script that obtains de IP from all the instances of ElasticBeanstalk apps/envs and adds them to the /etc/hosts of a server.
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/sh | |
#################################################### | |
# por: Christian Dechery | |
# objetivo: obtem os enderecos IP de todas as instancias de aplicacoes | |
# rodando no ElasticBeanstalk | |
################################################### | |
envs=("tecvirt" "hmlg" "mock" "hmlg2" "prod") | |
cat base_hosts > new_hosts | |
for env in ${envs[@]}; do | |
envinfo=`aws elasticbeanstalk describe-environment-resources --environment-name ${env} | jq '.EnvironmentResources| .Instances[]' | grep "Id"` | |
i=1 | |
while read -r line; do | |
instanceid=`echo $line | awk -F ':' '{print $2}' | tr -d '"'` | |
ip=`aws ec2 describe-instances --instance-ids ${instanceid} | jq -r '.Reservations[].Instances[].NetworkInterfaces[].PrivateIpAddress'` | |
echo "$ip $env-$i" >> new_hosts | |
((i+=1)) | |
done <<< "$envinfo" | |
done | |
sudo sh -c 'cat new_hosts > /etc/hosts' | |
rm new_hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment