Ruby on rails 4 AWSAccessKeyId未授权

Ruby on rails 4 AWSAccessKeyId未授权,ruby-on-rails-4,amazon-web-services,mechanicalturk,Ruby On Rails 4,Amazon Web Services,Mechanicalturk,我试图使用GET请求来使用Amazon Mechanical Turk函数。然而,我在尝试时得到了这个错误代码 AWS.NotAuthorized The identity contained in the request is not authorized to use this AWSAccessKeyId 这是我用来创建请求的代码 now = DateTime.now #For creating the signature hash data = "AWSMec

我试图使用GET请求来使用Amazon Mechanical Turk函数。然而,我在尝试时得到了这个错误代码

AWS.NotAuthorized The identity contained in the request is not authorized to use this AWSAccessKeyId
这是我用来创建请求的代码

    now = DateTime.now

    #For creating the signature hash
    data = "AWSMechanicalTurkRequesterGetFileUploadURL" + now.to_s
    sha256 = OpenSSL::Digest::SHA256.new
    sig = OpenSSL::HMAC.digest(sha256, Rails.configuration.secret_key, data)
    signature = Base64.encode64(sig)
    puts "https://mechanicalturk.amazonaws.com", "/?Service=AWSMechanicalTurkRequester&AWSAccessKeyId=#{Rails.configuration.aws_key}&Version=2014-08-15&Operation=GetFileUploadURL&Signature=#{sig}&Timestamp=#{now}&AssignmentId=#{mturk_results[0][:AssignmentId]}&QuestionIdentifier=file1"

    puts "\n\n"

    uri = URI('https://mechanicalturk.amazonaws.com')
    params = {:Service=>"AWSMechanicalTurkRequester", :AWSAccessKeyId=>Rails.configuration.aws_key, :Version=>"2014-08-15", :Operation=>"GetFileUPloadURL", :Signature=>sig, :Timestamp=>now, :AssignmentId=>mturk_results[0][:AssignmentId], :QuestionIdentifier=>"file1"}
    uri.query = URI.encode_www_form(params)
    res = 0
    Net::HTTP.start(uri.host, uri.port,
        :use_ssl => uri.scheme == 'https') do |http|
        request = Net::HTTP::Get.new uri

        res = http.request request # Net::HTTPResponse object
    end

你知道我做错了什么吗?

你需要正确设置时间戳的格式。时间戳必须采用UTC格式,并采用以下ISO 8601格式: YYYYMMDD'HHMMSS'Z'。例如,20150830T123600Z是一个有效的时间戳。不要在时间戳中包含毫秒

它需要采用以下形式: 时间戳=2016-04-23T08:00:05Z

而Ruby的DateTime.now方法返回的格式为: 2016-08-05T10:43:27-07:00

您可以在此处阅读有关时间戳和AWS签名的更多信息:

为什么不使用亚马逊或rturk的官方Ruby SDK?不管怎样,MTurk对日期格式非常挑剔,所以我认为这就是问题所在。我在Ruby SDK中找不到任何用于返回文件结果的函数。我从GethItREST中得到了一个上传的FrimeKEY,它包含了一个附加到一个基址的URL的一部分,但是我一直无法使用它。另一个要考虑的技巧是,在你的AWS调用签名时,我会使用一个超级简单的方法。GetAccountBalance是一个很好的候选人。更多信息请参见: