Invalid Amazon S3 date when used expire in url_for

I am creating a document in an Amazon s3 bucket. Then I am trying to create a signed url for that bucket that will expire after a few years like this:

s3 = AWS::S3.new(:access_key_id => S3Config.access_key_id, :secret_access_key => S3Config.secret_access_key)
    bucket = s3.buckets[S3Config.bucket]
    bucket.objects[s3_key].url_for(:read, :expires => Time.at(Time.utc(2019,12,30)).to_i)

      

But when I go to the signed URL, I get the following error:

Invalid date (should be seconds since epoch)

      

But according to the ruby ​​docs for Time.at and my understanding of the era, this should work ... what am I doing wrong?

+3


source to share


1 answer


The exception text may come from something deeper and ends up being misleading, the state of the docs and examples:

: expires (Object) - sets the expiration time of the URL; then S3 will return an error if a URL is used. It can be an integer (specify the number of seconds after the current time) , a string (which is parsed as a date using time # parsing), a time, or a DateTime object . This option defaults to one hour after the current time.



Based on this, I think you are working too hard, try this:

expires: Time.utc(2019, 12, 3)

      

+4


source







All Articles