Strange Timestamp issues using aws s3 with rails

1k Views Asked by At

I am using Dragonfly (https://github.com/markevans/dragonfly) for some image manipulation on a project and that uses fog as a data storage engine. I recently started getting weird Amazon errors on requests. The main errors are

AWS authentication requires a valid Date or x-amz-date header

and

The difference between the request time and the current time is too large.

This works fine on all my other machines, just on one development machine. Its running Mac OSX with Ruby 1.9 and Rails 3.0.10, the timestamps is fine on the machine. The header seems to be coming in as epoch time for some reason...

Full errors:

Excon::Errors::Forbidden (Expected(200) <=> Actual(403 Forbidden)
  request => {:connect_timeout=>60, 
  :headers=>{"Date"=>"Wed, 31 Dec 1969 23:59:59 +0000", "Authorization"=>"AWS AUTHKEY", "Host"=>"my-development.s3.amazonaws.com:443"}, :instrumentor_name=>"excon", :mock=>false, :nonblock=>true, :read_timeout=>60, :retry_limit=>4, :ssl_ca_file=>"/Users/temp/.rvm/gems/ruby-1.9.2-p180/gems/excon-0.16.2/data/cacert.pem", :ssl_verify_peer=>true, :write_timeout=>60, :host=>"my-development.s3.amazonaws.com", :path=>"/", :port=>"443", :query=>{}, :scheme=>"https", :expects=>200, :idempotent=>true, :method=>"GET", :response_block=>#<Proc:0x007fe4c3cc51f0@/Users/temp/.rvm/gems/ruby-1.9.2-p180/gems/fog-1.5.0/lib/fog/core/connection.rb:16 (lambda)>}
  response => #<Excon::Response:0x007fe4c3c77a18 @body="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>AWS authentication requires a valid Date or x-amz-date header</Message><RequestId>AF3S5E9BAA514F1</RequestId><HostId>SOMETHING</HostId></Error>", @headers={"x-amz-request-id"=>"AF3S5E9BAA514F1", "x-amz-id-2"=>"SOMETHING", "Content-Type"=>"application/xml", "Transfer-Encoding"=>"chunked", "Date"=>"Thu, 25 Oct 2012 19:03:39 GMT", "Server"=>"AmazonS3"}, @status=403>):


ERROR Excon::Errors::Forbidden: Expected([200, 206]) <=> Actual(403 Forbidden)   request => {:connect_timeout=>60, 
:headers=>{"Date"=>"Thu, 01 Jan 1970 00:00:01 +0000", "Authorization"=>"AWS AUTHKEY", "Host"=>"my-development.s3.amazonaws.com:443"}, :instrumentor_name=>"excon", :mock=>false, :nonblock=>true, :read_timeout=>60, :retry_limit=>4, :ssl_ca_file=>"/Users/temp/.rvm/gems/ruby-1.9.2-p180/gems/excon-0.16.2/data/cacert.pem", :ssl_verify_peer=>true, :write_timeout=>60, :host=>"my-development.s3.amazonaws.com", :path=>"/2012%2F10%2F18%2F19%2F32%2F28%2F836%2Fdragonfly20121018_47202_2lm4t0", :port=>"443", :query=>nil, :scheme=>"https", :expects=>[200, 206], :idempotent=>true, :method=>"GET"}   response =>
#<Excon::Response:0x007fd11e048ea8 @body="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>RequestTimeTooSkewed</Code><Message>The difference between the request time and the current time is too large.</Message><MaxAllowedSkewMilliseconds>900000</MaxAllowedSkewMilliseconds><RequestId>85D12B885D8B4DBE</RequestId><HostId></HostId><RequestTime>Thu, 01 Jan 1970 00:00:01
+0000</RequestTime><ServerTime>2012-10-26T21:19:18Z</ServerTime></Error>", @headers={"x-amz-request-id"=>"85D12B885D8B4DBE", "x-amz-id-2"=>"SOMETHING", "Content-Type"=>"application/xml", "Transfer-Encoding"=>"chunked", "Date"=>"Fri, 26 Oct 2012 21:19:16 GMT", "Server"=>"AmazonS3"}, @status=403>
2

There are 2 best solutions below

0
On

http://www.bucketexplorer.com/documentation/amazon-s3--difference-between-requesttime-currenttime-too-large.html

Just change your machine local time with UTC time or with server time.

It helps me to solve above error.

0
On

No clue why, I didnt change anything on my end, I didnt even restart my application, but it started working today.