Created
December 4, 2014 16:10
-
-
Save noda-sin/b63434a03adf68920d51 to your computer and use it in GitHub Desktop.
AWS Command Tools
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
#!/bin/sh | |
selfId=$(curl http://169.254.169.254/latest/meta-data/instance-id) | |
allocIds=$(aws ec2 describe-addresses | jq '[.Addresses[] | select(.AssociationId == null) | .AllocationId]') | |
allocLen=$(echo ${allocIds} | jq length) | |
if [ "${allocLen}" -eq 0 ]; then | |
echo 'Allocation address not found' 1>&2 | |
exit 2 | |
fi | |
allocId=$(echo ${allocIds} | jq -r .[1]) | |
aws ec2 associate-address --instance-id ${selfId} --allocation-id ${allocId} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment