Add a VPC node to ELB programmatically

安稳与你 提交于 2020-01-04 02:41:11

问题


The following code is intended to add a newly deployed EC2 instance in a VPC to a load balancer. (This is pretty obviously test/dummy code, but the general workflow is the same in a real system)

require 'yaml'
gem 'aws-sdk','1.6.0'
require 'aws-sdk'

AWS.config({
  :access_key_id => KEY,
  :secret_access_key => SECRET_KEY
})
ec2 = AWS::EC2.new
elb = AWS::ELB.new

i = ec2.instances["i-abcd1234"]
elb.load_balancers["lb-name"].instances.register(i)

When I run this code, I get this error:

AWS::ELB::Errors::ValidationError: ELB in VPC is not supported in this version of API. Please try 2011-11-15 or newer.

My aws-sdk gem is the most current version available through RubyGems, it was updated this week. Is this just not a feature available in the Ruby SDK for AWS? What can I do to add a VPC node to a Load Balancer with Ruby code, through this gem or otherwise?


回答1:


Resolved: This error was the result of the ELB portion of the aws-sdk gem using an old version of the AWS API. A new gem version (1.6.1) was released on August 6, 2012 which causes ELB to use the 2012-06-01 version of the API, and now instances can be added to an ELB using code like in the question.



来源:https://stackoverflow.com/questions/11800472/add-a-vpc-node-to-elb-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!