4
votes

I'm building a rails3 app on heroku, and I'm using aws-s3 gem to manipulate files stored in an Amazon S3 eu bucket.

When I try to perform a AWS::S3::S3Object.delete filename, 'mybucketname' command, I get the following error:

AWS::S3::PermanentRedirect (The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.):

I have added the following to my application.rb file:

 AWS::S3::Base.establish_connection!(  
   :access_key_id     => "myAccessKey",  
   :secret_access_key => "mySecretAccessKey" 
 )

and the following code to my controller:

def destroy song = tape.songs.find(params[:id])

AWS::S3::S3Object.delete song.filename, 'mybucket'

song.destroy


respond_to do |format|  
    format.js   { render :nothing => true } 
  end     end

I found a proposed solution somewhere to add AWS_CALLING_FORMAT: SUBDOMAIN to my amazon_s3.yml file, as supposedly, aws-s3 should handle differently eu buckets than us. However, this did not work, same error is received.

Could you please provide any assistance? Thank you very much for your help.

3

3 Answers

3
votes

the problem is you need to type SUBDOMAIN as uppercase string in config, try this out

1
votes

You can specify custom endpoint at connection initialization point:

    AWS::S3::Base.establish_connection!(
      :access_key_id     => 'myAccessKey',
      :secret_access_key => 'mySecretAccessKey',
      :server            => 's3-website-us-west-1.amazonaws.com'
    )

you can find actual endpoint through the AWS console:

enter image description here

full list of valid options - here https://github.com/marcel/aws-s3/blob/master/lib/aws/s3/connection.rb#L252

VALID_OPTIONS = [:access_key_id, :secret_access_key, :server, :port, :use_ssl, :persistent, :proxy].freeze
0
votes

My solution is to set the constant to the actual service link at initialization time. in config/initializers/aws_s3.rb

  AWS::S3::DEFAULT_HOST = "s3-ap-northeast-1.amazonaws.com"
  AWS::S3::Base.establish_connection!(
      :access_key_id     => 'access_key_id',
      :secret_access_key => 'secret_access_key'
  )