Search code examples
amazon-web-servicesamazon-s3slidingexpiration

S3 presigned url with sliding expiration


We can create S3 presigned url either using default 1 hour lifetime or custom lifetime.

But, can we create an S3 presigned url with sliding expiration?

EDIT:

If the lifetime of the url is 10 minutes and if it is accessed at the 9th minute, its lifetime should extend further by another 10 minutes (i.e., till 19th minute) and so on.


Solution

  • There isn't any way. From the documentation on the pre-signed Amazon S3 request mentions that the query string must include the AWS access key, the signature, and the expiration timestamp, and the timestamp is defined simply as:

    The time when the signature expires, specified as the number of seconds since the epoch (00:00:00 UTC on January 1, 1970). A request received after this time (according to the server) will be rejected.

    Since this is part of the input to the signature function, it cannot change, and since it only allows for a specific timestamp in the future, you can only sign a S3 URL with a specific time.

    And as an aside: That's true for both the common v2 links and the v4 links. The v4 link looks a bit different, but it still requires a specific number of seconds from a specific expiration timestamp, pinning links it creates to a specific timestamp just like v2.