Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "uninitialized constant AWS (NameError)"

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 initializers/aws.rb file:

AWS.config(:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
                      :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'])

s3 = AWS::S3.new
AVATAR_BUCKET = s3.buckets[ENV['AVATAR_BUCKET_NAME']]

When I try running the server or opening the console I get this error:

/initializers/aws.rb:1:in `': uninitialized constant AWS (NameError)

like image 887
bezzoon Avatar asked Apr 03 '14 01:04

bezzoon


3 Answers

If you are receiving this error and you have the "aws-sdk" gem installed, you likely have upgraded to version 2 of the aws-sdk gem unintentionally. Version 2 uses the Aws namespace, not AWS. This allows version 1 and version 2 to be used in the same application.

See this blog post for more information.

like image 51
Trevor Rowe Avatar answered Oct 20 '22 09:10

Trevor Rowe


You need to install/use the -v1 version of aws-sdk. Simply doing gem 'aws-sdk' or require 'aws-sdk' may use the 2.x version of aws-sdk instead.

To avoid any confusion, for scripts that require 1.x, use:

require 'aws-sdk-v1' # not 'aws-sdk'

And for scripts that require 2.x, use:

gem 'aws-sdk', '~> 2'

as the GitHub documentation indicates.

like image 24
DrStrangepork Avatar answered Oct 20 '22 10:10

DrStrangepork


You might getting this error, because you didn't define the correct aws sdk version in your Gemfile. This can happen while re-bundling old apps with version 1 or 2 installed.

Make sure which version you want to install:

aws-sdk version 3

gem 'aws-sdk', '~> 3'

# call sdk    
Aws.<whatever>

aws-sdk version 2

gem 'aws-sdk', '~> 2'

# call sdk    
Aws.<whatever>

aws-sdk version 1

# version constraint
gem 'aws-sdk', '< 2'

# or 

# use the v1 gem
gem 'aws-sdk-v1'

# call sdk    
AWS.<whatever>

v1 is scoped under AWS and v2 and v3 scoped under Aws => That allows you to run v1 and v2 side by side.

like image 17
Simon Franzen Avatar answered Oct 20 '22 11:10

Simon Franzen