We use cookies to personalize content and ads, to offer features for social media and to analyze the access to our website. We also share information about your use of our website with our social media, weaving and analytics partners. Our partners may combine this information with other information that you have provided to them or that they have collected as part of your use of the Services. You accept our cookies when you click "Allow cookies" and continue to use this website.

Allow cookies Privacy Policy

Ruby legacy code: Using the right AWS Ruby SDK version

You might have updated a RubyOnRails app recently and now your AWS gem is not working anymore. So AWS is an uninitialized constant? Read this!


We have been developing and maintaining RubyOnRails Apps since 2012. If you do long-term support for projects, security updates and further developments are scheduled at regular intervals. As your own projects evolve, so do the services and plugins you use.

Of course, a "bundle update" command is not enough to bring an app up to date. It is recommended to go step by step through the used services and plugins, take deprecated hints seriously and gradually install the new versions. 

A typical example is Amazon Web Services. Meanwhile the SDK is at version 3 and as it of course always happens: 

  • Your own app could already use the new SDK version, but some plugins don't yet. 
  • Or you have accidentally updated to the new version and now the SDK is no longer available.

The typical error when working with AWS legacy code:

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

You might getting this error, because you didn't define the correct AWS Ruby 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-SDK version 2

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

AWS-SDK version 1

# version constraint
gem 'aws-sdk', '< 2'
# or 
# use the v1 gem
gem 'aws-sdk-v1'
# call sdk    

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

I hope this example shows you how important it is to take updates of your apps seriously and that you, please, please, have a good test coverage. Failing tests are your life safers during updates. 


Share this article:

zauberware logo