Last active
November 16, 2015 02:48
-
-
Save tsaito-cyber/d11aae718662ca97c4c9 to your computer and use it in GitHub Desktop.
change-ip-by-eip.sh
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/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