Skip to content

Instantly share code, notes, and snippets.

@tsaito-cyber
Last active November 16, 2015 02:48
Show Gist options
  • Save tsaito-cyber/d11aae718662ca97c4c9 to your computer and use it in GitHub Desktop.
Save tsaito-cyber/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