Yet another one DevOps blog

Ops and DevOps stories

Jun 7, 2013 - 1 minute read - Comments - technical aws amazon ruby

Manage AWS Elastic IPs with AWS Ruby SDK

I tried three ruby libs for managing Elastic IPs for AWS EC2.

  • fog
  • right_aws
  • Official Ruby AWS SDK.

I wholeheartedly recommend Official AWS Ruby SDK, as most simple and easy to use. I also insert several examples of assigning Elastic IPs with AWS Ruby SDK:

Connect to AWS API with AWS Ruby SDK.

c = AWS::EC2.new(:access_key_id => "AWS_access_key", :secret_access_key => "AWS_secret_key", :region => "us-east-1")

Associate Elastic IP

x.x.x.x in this example is your Elastic IP address

eip = c.elastic_ips["x.x.x.x"]
eip.associate :instance => "Your instance id"

Disassociate Elastic IP

x.x.x.x in this example is your Elastic IP address

eip = c.elastic_ips["x.x.x.x"]
eip.disassociate

Further reading

AWS Ruby SDK