Skip to content

Instantly share code, notes, and snippets.

@seventhskye
Created September 28, 2016 13:23
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 seventhskye/a9da24ad87f8cd4ecb4dbd2c0e2918ab to your computer and use it in GitHub Desktop.
Save seventhskye/a9da24ad87f8cd4ecb4dbd2c0e2918ab to your computer and use it in GitHub Desktop.
Script to update an EC2 instance with an elastic IP.
#!/usr/bin/env python
import boto3
import requests
def main(argv):
instance_id = requests.get('http://169.254.169.254/latest/meta-data/instance-id').text
allocation_id = argv[1]
client = boto3.client('ec2')
response = client.associate_address(InstanceId=instance_id,AllocationId=allocation_id)
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment