Created
June 21, 2017 02:04
-
-
Save qfgaohao/017cee8ac6c4aa487313eabd319b02fe to your computer and use it in GitHub Desktop.
Rotate elastic ips for an EC2 Machine
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
client = boto3.client('ec2') | |
instance_id = 'my instance id' | |
def rotate_ip(last_eip=None): | |
if last_eip: | |
client.release_address(AllocationId=last_eip['AllocationId']) | |
eip = client.allocate_address(Domain='vpc') | |
r = client.associate_address(AllocationId=eip['AllocationId'], InstanceId=instance_id) | |
return eip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment