Skip to content

Instantly share code, notes, and snippets.

@qfgaohao
Created June 21, 2017 02:04
Show Gist options
  • Save qfgaohao/017cee8ac6c4aa487313eabd319b02fe to your computer and use it in GitHub Desktop.
Save qfgaohao/017cee8ac6c4aa487313eabd319b02fe to your computer and use it in GitHub Desktop.
Rotate elastic ips for an EC2 Machine
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