I have been trying to set a expiration time once I send a request to AWS in order to create a Pre-signed URL; However, I don't get the Pre-signed URL expired as the time I need.
Here is some code I use from AWS:
java.util.Date expiration = new java.util.Date();
long expTimeMillis = Instant.now().toEpochMilli();
expTimeMillis = 1000;
System.out.println("expired Time:" expTimeMillis);
expiration.setTime(expTimeMillis);
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key)
.withMethod(HttpMethod.GET).withExpiration(expiration);
URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
After sending that request to AWS, I got this pre-signed URL:
https://BucketName.amazonaws.com/ABC/DEF/ABC.csv
?response-content-disposition=attachment; filename ABC.csv"
&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20221005T024318Z&X-Amz-SignedHeaders=host
&X-Amz-Expires=0&X-Amz-Credential=AASDus-east-1/s3/aws4_request
&X-Amz-Signature=HHHHH
I was able to download the file and able to use that presigned URL after 5 minutes also. However, after 10 minutes or so, I got this message. If I am not missing anything, I expected to get this message after 1 second instead of after 10 minutes.
<Error>
<Code>AccessDenied</Code>
<Message>Request has expired</Message>
<X-Amz-Expires>0</X-Amz-Expires>
<Expires>2022-10-05T02:43:18Z</Expires>
<ServerTime>2022-10-05T02:45:01Z</ServerTime>
<RequestId>RequestID</RequestId>
<HostId>Host</HostId>
</Error>
CodePudding user response:
It might be due to clock drift on your computer -- check that it is set automatically from a Time Server.
Sometimes people create pre-signed URLs using the wrong timezone (AWS uses UTC), so confirm that the time used in the URL is in UTC.