Skip to content

Instantly share code, notes, and snippets.

@noda-sin
Created December 4, 2014 16:10
Show Gist options
  • Save noda-sin/b63434a03adf68920d51 to your computer and use it in GitHub Desktop.
Save noda-sin/b63434a03adf68920d51 to your computer and use it in GitHub Desktop.
AWS Command Tools
#!/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