Skip to content

Instantly share code, notes, and snippets.

@takuma-saito
Last active November 16, 2015 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuma-saito/d11aae718662ca97c4c9 to your computer and use it in GitHub Desktop.
Save takuma-saito/d11aae718662ca97c4c9 to your computer and use it in GitHub Desktop.
change-ip-by-eip.sh
#!/bin/zsh
InstanceId="$1"
# allocation id of current ip
OldAllocationId=$(aws ec2 describe-addresses |
jq -r '.Addresses[] | select(.InstanceId == "'$InstanceId'") | .AllocationId')
# create address
NewAllocationId=$(aws ec2 allocate-address | jq -r '.AllocationId')
echo new:$NewAllocationId old:$OldAllocationId
aws ec2 associate-address --instance-id $InstanceId --allocation-id $NewAllocationId
aws ec2 release-address --allocation-id $OldAllocationId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment