DevOp's Blog

jakshi's devop blog.

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

Comments