16

This is an issue I'm having with the fact that after I upgraded to AWS-SDK (instead of aws-s3) with the newer version(s) of paperclip I can no longer call AWS::S3::Base.establish_connection! at all.

Where ever in my code I call

AWS::S3::Base.establish_connection!(:access_key_id => '****', :secret_access_key => '***')

I get this error...

NameError (uninitialized constant AWS::S3::Base):
    app/models/asset.rb:28:in `move_upload_from_temp_to_final_resting_place'
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Keith Connolly
  • 386
  • 2
  • 9

3 Answers3

22

Yeah, aws-sdk doesn't have AWS::S3::Base. I think this is the closest equivalent:

s3 = AWS::S3.new(:access_key_id => '****', :secret_access_key => '***')
rcrogers
  • 2,281
  • 1
  • 17
  • 14
  • 1
    This is correct. The aws-sdk maintains its own persistent connection pool, no need to explicitly establish a connection. – Trevor Rowe Apr 17 '12 at 03:53
  • I originally fixed it by downgrading all my AWS code to very early versions. But I was able to upgrade again, using this and get things working nicely with both my aJAX uploader and my EBAY API gem. Thanks. – Keith Connolly May 08 '12 at 19:21
  • Thank you. It saved a couple of hours of searching :) – Salil Jun 27 '12 at 01:18
2

As this was the first page that popped up for me on my google search to solve this issue I will comment on how I managed to solve it. Under the AWS SDK 2.0.47

require 'rubygems'
require 'aws/s3'

include AWS::S3

AWS::S3::Base.establish_connection!(
   :access_key_id => '',
   :secret_access_key => ''
)

I was simply missing the include AWS::S3. And I suspect many people are running into this issue as I have yet to see a straight foward answer.

Konstantino Sparakis
  • 2,862
  • 3
  • 18
  • 30
0

I tried Konstantino solution but, unfortunately, it didn't work for me. using include AWS::S3 threw the following exception.

TypeError: wrong argument type Class (expected Module)

This is how I solved the same issue

AWS.send(:remove_const, :S3) if AWS::S3.class == Class
require Gem::Specification.find_by_name("aws-s3").gem_dir + "/lib/aws/s3.rb"

as I was using aws-s3's modules and methods in another method that was initiated using delayed_job, this patch didn't create issue in my case. But this can create issues in another use case as aws-sdk's class is now replaced with aws-s3's module.

Kinaan Khan Sherwani
  • 1,504
  • 16
  • 28