【发布时间】:2022-02-02 03:58:33
【问题描述】:
我正在尝试从生产服务器访问我的 S3 存储桶。在开发中一切正常,但是在我的产品控制台中,我得到了:
Aws::S3::Errors::AuthorizationHeaderMalformed: The authorization header is malformed; the Credential is mal-formed; expecting "<YOUR-AKID>/YYYYMMDD/REGION/SERVICE/aws4_request".
我的代码:
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
我的 aws 初始化程序(似乎在两种环境中都可以正常工作):
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)
})
感谢任何建议!
【问题讨论】:
-
找到一种方法来查看正在发送的实际请求。此时解决方案应该很直观。
标签: ruby-on-rails ruby amazon-web-services amazon-s3