Skip to content

Instantly share code, notes, and snippets.

@QROkes
Last active December 24, 2017 22:21
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 QROkes/d9fcfb26c2890bd15935 to your computer and use it in GitHub Desktop.
Save QROkes/d9fcfb26c2890bd15935 to your computer and use it in GitHub Desktop.
Automatically associate an elastic IP to an EC2 instance.
# Please, enable "Multiverse" in /etc/apt/sources.list
# Add the AWS PPA - sudo apt-add-repository ppa:awstools-dev/awstools
# Update and then install - sudo apt-get update && sudo apt-get install ec2-api-tools
# Upload your AWS Credential (PEM files)
# Save this script in /etc/rc.local
export EC2_KEYPAIR=<name only-not the file name>
export EC2_URL=https://ec2.us-east-1.amazonaws.com
export EC2_PRIVATE_KEY=/var/opt/ec2/<pk-filename.pem>
export EC2_CERT=/var/opt/ec2/<cert-filename.pem>
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
export AWS_ACCESS_KEY=<Your AWS S3 access key>
export AWS_SECRET_KEY=<Your AWS S3 secret key>
instanceid=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/instance-id`
ec2-associate-address -i $instanceid <Your elastic IP>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment