Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 in rails - how to set the s3_signature_version parameter

I'm trying to set up the Amazon Simple Storage Service for use with rails. I'm getting this error message:

The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.

The problem is that I chose the Frankfurt S3 region, and there only the V4 scheme is supported. It's the same error message as in this post, which directs you to the solution here, with instructions how to "set the :s3_signature_version parameter to :v4 when constructing the client". The command is:

s3 = AWS::S3::Client.new(:s3_signature_version => :v4)

My question is, how do I do this? Where do I put this code?

EDIT:

I tried putting :s3_signature_version => :v4 in carrier_wave.rb as follows, but during the upload to heroku it said [fog][WARNING] Unrecognized arguments: s3_signature_version, and it didn't make any difference, I still get the error.

config/initializers/carrier_wave.rb:

    if Rails.env.production?
      CarrierWave.configure do |config|
        config.fog_credentials = {
          # Configuration for Amazon S3
          :provider              => 'AWS',
          :aws_access_key_id     => ENV['S3_ACCESS_KEY'],
          :aws_secret_access_key => ENV['S3_SECRET_KEY'],
          :s3_signature_version  => :v4
        }
        config.fog_directory     =  ENV['S3_BUCKET']
      end
    end

EDIT:

I've created a new bucket using the Northern California region, for which this isn't supposed to be a problem, but I'm still getting exactly the same error message.

EDIT:

This doesn't make any difference either:

    if Rails.env.production?
      CarrierWave.configure do |config|
        config.fog_credentials = {
          # Configuration for Amazon S3
          :provider              => 'AWS',
          :aws_access_key_id     => ENV['S3_ACCESS_KEY'],
          :aws_secret_access_key => ENV['S3_SECRET_KEY']
        }
        config.fog_directory     =  ENV['S3_BUCKET']
        config.fog_attributes = {:s3_signature_version => :v4}
      end
    end
like image 677
Bazley Avatar asked Jan 08 '15 19:01

Bazley


1 Answers

I had the problem, that Spree v2.3 was fixated to aws-sdk v1.27.0. But the parameter s3_signature_version was introduced in v1.31.0 (and set per default for China).

So in my case the following configuration for Frankfurt has totally been ignored:

AWS.config(
    region: 'eu-central-1',
    s3_signature_version: :v4
)
like image 138
schmijos Avatar answered Nov 15 '22 20:11

schmijos