I have created a function to get a link to download an object in S3.
def get_presigned_url(s3_bucket, s3_object_key, expiration_seconds):
url = boto3.client('s3', config=Config(signature_version='s3v4'),
aws_access_key_id='access_key_id',
aws_secret_access_key='secret_access_key').generate_presigned_url(
ClientMethod='get_object',
Params={'Bucket': s3_bucket, 'Key': s3_object_key},
ExpiresIn=expiration_seconds)
return url
It creates the link with the correct expiry time (90 hours) but after 20 hours the link stops working.
Can someone help me?
2
Answers
PreSigned URL created using
If you created a presigned URL by using a temporary token, then the URL expires when the token expires, even if you created the URL with a later expiration time.
Ref: https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html#PresignedUrl-Expiration
Alternatively, override the session and create a client using that session as below
I’m not sure what’s happening with your code, but here is a sample Python program based on your code:
The output is:
You’ll notice that is is displaying the EXACT Access Key that was passed into the function (
AKIA123
). Generating a pre-signed URL does not actually involve making a call to AWS. Rather, it is just using a hash function and the Secret Key to ‘sign’ the request.Yet, strangely, your code is returning an
ASIA
key. I think you are not running the code you have shown us. Try running the above code and you’ll see.