0

We want to export our ELB configurations for re-use. I can get the ELB configs with:

all_elbs = Fog::AWS::ELB.load_balancers.all()

But this returns a failure:

all_policies = Fog::AWS::ELB.policies.all()
#=> /Library/Ruby/Gems/2.0.0/gems/fog-aws-0.0.6/lib/fog/aws/models/elb/policies.rb:20:
#=> in `munged_data': undefined method `reduce' for nil:NilClass (NoMethodError)

Ultimately, I want to be able to recreate a ELB based on an existing ELB.

Phrogz
  • 296,393
  • 112
  • 651
  • 745

1 Answers1

0

That error message means that on line 20 of policies.rb there is code like foo.reduce and foo happens to be nil.

If we look at the source code of the gem, we see:

def munged_data
  data.reduce([]){ |m,e|  # line 20

So, the problem is that data is nil when the munged_data method is called. We see on line 8 of the same file that data is defined via a simple attr_accessor call. I cannot tell for sure where that should have been set. (There are 227 instances of @data = or data = in the gem.) This seems like a bug in the AWS gem, unless you were supposed to call some method before calling .all on policies.


Tracing further, we see that policies is defined in load_balancer.rb on line 154 as:

def policies
  Fog::AWS::ELB::Policies.new({
    :data => policy_descriptions,
    :service => service,
    :load_balancer => self
  })
end

Assuming that the data passed to the method is used directly as the @data instance variable, then the problem is that policy_descriptions returned nil.

The implementation of policy_descriptions is:

def policy_descriptions
  requires :id
  @policy_descriptions ||= service.describe_load_balancer_policies(id).body["DescribeLoadBalancerPoliciesResult"]["PolicyDescriptions"]
end

If service.describe_load_balancer_policies(id).body["DescribeLoadBalancerPoliciesResult"] returned nil (or any object that did not have a [] method) this method would have thrown an error. So, my deduction is that this returned something like a hash, but that hash has no "PolicyDescriptions" key.

From there...I don't know.

halfer
  • 19,824
  • 17
  • 99
  • 186
Phrogz
  • 296,393
  • 112
  • 651
  • 745