Reputation: 1021
I'm now completely confused with AWS NameError after I updated bundle in Ruby. The command was bundle update.
The below is my Gemfile.lock
DEPENDENCIES
actionmailer_inline_css
aws-sdk
...
awesome_print (1.6.1)
aws-sdk (2.3.9)
aws-sdk-resources (= 2.3.9)
aws-sdk-core (2.3.9)
jmespath (~> 1.0)
aws-sdk-resources (2.3.9)
aws-sdk-core (= 2.3.9)
.
My Gemfile includes
gem 'aws-sdk'
However I have no idea why suddenly this problem occurred. Are there anyone having this issue before and ending up fixing this error? please share with me! I'm desperate to fix this problem..
I have aws.rb file in the initializers.
AWS.config(
#:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:access_key_id => 'XX',
#:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
:secret_access_key => 'X/X/X/X'
)
#S3_BUCKET = AWS::S3.new.buckets[ENV['S3_BUCKET']]
S3_BUCKET = AWS::S3.new.buckets['XX']
Ruby version is 2.1.5 The entire error message when typing rails s is as follow:
/Users/sungpah/XX/config/initializers/aws.rb:1:in `<top (required)>': uninitialized constant AWS (NameError)
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/notifications.rb:166:in `instrument'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:651:in `load_config_initializer'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.1/lib/active_support/notifications.rb:166:in `instrument'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:651:in `load_config_initializer'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:615:in `each'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/engine.rb:615:in `block in <class:Engine>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `each'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `tsort_each_child'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:411:in `call'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /Users/sungpah/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
from /Users/sungpah/ringle/config/environment.rb:5:in `<top (required)>'
from /Users/sungpah/ringle/config.ru:3:in `block in <main>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
from /Users/sungpah/ringle/config.ru:in `new'
from /Users/sungpah/ringle/config.ru:in `<main>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/server.rb:61:in `app'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/server.rb:78:in `start'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `server'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/sungpah/ringle/bin/rails:8:in `require'
from /Users/sungpah/ringle/bin/rails:8:in `<top (required)>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `load'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `call'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/client/command.rb:7:in `call'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/client.rb:30:in `run'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/bin/spring:49:in `<top (required)>'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `load'
from /Users/sungpah/.rvm/gems/ruby-2.1.5/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `<top (required)>'
from /Users/sungpah/ringle/bin/spring:13:in `require'
from /Users/sungpah/ringle/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
Upvotes: 1
Views: 1678
Reputation: 8042
Upgrading from the Amazon AWS SDK v1 to v2 contains a few surprises. The most immediately impacting surprise is that the name AWS
was changed to Aws
, requiring code changes in order to simply update the gem.
The AWS SDK for Ruby - Version 2 guide will help with the details. The very first entry in this guide concerns the NameError: uninitialized constant AWS
error that you encountered. An overview of the list of changes, features, and improvements of the AWS SDK v2 are documented in Announcing V2 of the AWS SDK for Ruby, and that's worth a read to know what to expect.
Note that you can continue using the AWS SDK v1 alongside the AWS SDK v2 gem if you like, simply by including both gems in your Gemfile
:
gem 'aws-sdk', '~> 2'
gem 'aws-sdk-v1'
This will allow your existing code to work without changes. That's definitely a good thing. Note that to continue using the v1 gem, you have to now refer to it as aws-sdk-v1
in the Gemfile
. This is a nice feature, and will allow you to migrate completely to the v2 gem on your own schedule, while still being able to use the new v2 features immediately.
Step back and consider whether you're fully aware of what's in the new gem, and why you want to upgrade. Once you do that, you may find that it's simply not the right time for an upgrade. New versions are not always better, and sometimes upgrading a component can heavily impact a project. Consider biting off a small research project to investigate the real impact of upgrading to the gem version; you may find that it's not even necessary, especially if you don't have requirements that make use exclusively of the new gem version's features.
Upvotes: 1
Reputation: 1044
Change initialiser code inside aws.rb to
Aws.config.update({
credentials: Aws::Credentials.new(
ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
})
Upvotes: 1
Reputation: 14543
The issue is you have to use "Aws" instead of "AWS" for version 2 AWS SDK see below use the below code. AWS SDK Version 2 uses the "Aws" namespace, not "AWS".
Aws.config(
#:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:access_key_id => 'XXXXXXXXX',
#:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
:secret_access_key => 'XXXXXXX'
)
#S3_BUCKET = AWS::S3.new.buckets[ENV['S3_BUCKET']]
S3_BUCKET = Aws::S3.new.buckets['ringlecourse']
Also read this documentation for AWS SDK upgrades http://docs.aws.amazon.com/sdkforruby/api/
Upvotes: 1