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
- GitHub: AWS Ruby SDK Examples
- AWS Docs: AWS Ruby SDK Getting Started
- AWS Docs: AWS Ruby SDK
- AWS Docs: AWS Ruby SDK Class: AWS::EC2::ElasticIpCollection
- AWS Docs: AWS Ruby SDK Class: AWS::EC2::ElasticIp
- AWS Docs: AWS Ruby SDK Class: AWS::Core::Configuration.initialize
- AWS Docs: AWS Ruby SDK Class: AWS::EC2
- RubyGems: AWS Ruby SDK