Error “uninitialized constant AWS (NameError)”

前端 未结 7 1762
梦毁少年i
梦毁少年i 2021-02-06 21:39

It is saying AWS is uninitialized. I am usign the aws-sdk-core gem.

I tried using the aws-sdk gem instead, and the problem was still there.

This is the initializ

7条回答
  •  既然无缘
    2021-02-06 22:38

    I encountered this problem in a Chef recipe, so the response below is decidedly Chef-centric.

    Amazon released version 2 of the aws-sdk in early February 2015. Version 2 is not entirely backwards compatible with version 1.

    So, you must make a decision - are you content with version 1 functionality, or do you want version 2 functionality?

    If you are content with version 1, perhaps for the short term, it is necessary to have Chef explicitly load version 1, because by default, it appears to use the latest version. To do this you must specify the version attribute to load in the recipe that loads chef_gem aws-sdk. The modification looks like this (probably implemented in a default.rb for the cookbook in question):

    chef_gem "aws-sdk" do
      action :nothing
    
      # Source:  https://aws.amazon.com/releasenotes/Ruby?browse=1
      version '1.62.0'  
    
    end.run_action(:install)
    

    Update the version in the cookbook's metadata, then upload the cookbook to your Chef server. Update the cookbook version in the environment, then upload the environment to your Chef server.

    After convergence, run a gem list on your instance to see the gem versions:

    On PowerShell PS C:\Users\Administrator> gem list | select-string aws-sdk

    On Linux: gem list | grep -i aws-sdk

    These are typical results:

    aws-sdk (2.0.27, 1.62.0) 
    aws-sdk-core (2.0.27) 
    aws-sdk-resources (2.0.27) 
    aws-sdk-v1 (1.62.0)
    

    Note that the last one specifies aws-sdk-v1. Now, you must update your recipe to require the older version of aws-sdk. Change this:

    require 'aws-sdk'
    

    to this:

    require 'aws-sdk-v1'
    

    Update the version in the metadata.rb, upload the cookbook, update the version in the environment file, upload the environment, and you should be good to go after the next convergence.

    This blog post contains more details and solutions to this problem: http://ruby.awsblog.com/post/TxFKSK2QJE6RPZ/Upcoming-Stable-Release-of-AWS-SDK-for-Ruby-Version-2

提交回复
热议问题