Amazon S3 - How do I check if a designated URL expires?

If I have a generated given URL that has expired, should I do get_headers() (in PHP) to see if a 403 Forbidden error has been selected, otherwise use the same URL? Or is this a bad idea because it is an unnecessary GET request? Should I always just update the new assigned URL every time? I'm a little confused because there seems to be not much information about this.

+5
source share
1 answer

The URL has a time period during which it expires.

Signature Version 2

htt ps: //bucket.s3.amazonaws.com/foo.txt? AWSAccessKeyId = AKIAABCDEFGHIJK & Expires = 1508608760 & Signature = xxxxxxxxxxx

Expires gives time in UTC.

 $ date -d @1508608760 Sat Oct 21 17:59:20 UTC 2017 

You can extract the value and compare it with the current time in UTC [ time() ], and then decide whether or not to recover.


Signature Version 4

HTT ps: //s3.amazonaws.com/bucket/foo.txt X-Amz-Algorithm = AWS4-HMAC-SHA256 & X-Amz-Expires = 3600 & X-Amz-credentials = AKIAJRZXXXXXXXXXus-east-1% 2Fs3% 2Faws4_request & X-Amz-SignedHeaders = host & X-Amz-Date = 20171021T190750Z & X- Amz-Signature = 8b84ae9b59e9f8a8d7066ecc39e797c8dc29848abcdef61717

X-Amz-Date gives UTC time in ISO 8601 format.

You can extract the value, convert it to the / UTC era and compare it with the current time in UTC [time ()], and then regenerate it or not.

+5
source

Source: https://habr.com/ru/post/1272794/


All Articles