I am trying to access my S3 bucket from a production server. Everything works fine in development, however in my prod console I am getting:
Aws::S3::Errors::AuthorizationHeaderMalformed: The authorization header is malformed; the Credential is mal-formed; expecting "<YOUR-AKID>/YYYYMMDD/REGION/SERVICE/aws4_request".
My code:
class AwsFileDownloader
def initialize(args)
@s3 = Aws::S3::Client.new
@aws_file_path = ...
end
def get_file
temp_file = File.new('temp.csv', 'r+')
@s3.get_object({bucket: Rails.application.secrets.aws_bucket, key: @aws_file_path}, target: temp_file)
...
end
end
My aws initializer (which seems to work fine in both environments):
require 'aws-sdk'
Aws.config.update({
region: Rails.application.secrets.aws_region,
credentials: Aws::Credentials.new(Rails.application.secrets.access_key_id, Rails.application.secrets.secret_access_key)
})
appreciate any advice!
This answer is very late but maybe someone will find it useful. The above error is caused when you switch up the AWS KEY ID
and the AWS ACCESS KEY
.
Use the correct credential in the right place and it should fix your issue.
Things to check:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With