Wir verwenden Cookies, um Inhalte und Anzeigen zu personalisieren, Funktionen für soziale Medien anbieten zu können und die Zugriffe auf unsere Webseite zu analysieren. Außerdem geben wir Informationen zu Ihrer Verwendung unserer Webseite an unsere Partner für soziale Medien, Webung und Analysen weiter. Unsere Partner führen diese Informationen möglicherweise mit weiteren Daten zusammen, die Sie ihnen bereitgestellt haben oder die sie im Rahmen Ihrer Nutzung der Dienste gesammelt haben. Sie akzeptieren unsere Cookies, wenn sie "Cookies zulassen" klicken und damit fortfahren diese Webseite zu nutzen.

Cookies zulassen Datenschutzerklärung

Ruby legacy code: Using the right AWS 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?

Coding

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 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.

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. 

Links:

Teile diesen Artikel:

zauberware logo