Question:
I have tried to generate pre-signed URL
with 7dsys expiration time.
(It is saying maximum duration is 7days, AWS S3 pre signed URL without Expiry date)
1 2 3 4 5 6 7 |
# It is called and retruned in AWS Lambda boto3.client('s3').generate_presigned_url( 'get_object', Params={'Bucket': bucket, 'Key': object_key}, ExpiresIn=(60*60*24*7) # 7days ) |
However, it seems not to retain the pre-signed URL
for 7days but just several hours. The pre-signed URL
just returns the XML format after that.
1 2 3 4 5 6 7 8 |
ExpiredToken . . . |
It seems even to be different expiration time every time I try, sometimes 5 hours, sometime 12hours.
I don’t know why.
Answer:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import boto3 from botocore.client import Config # Get the service client with sigv4 configured s3 = boto3.client('s3', config=Config(signature_version='s3v4')) # Generate the URL to get 'key-name' from 'bucket-name' # URL expires in 604800 seconds (seven days) url = s3.generate_presigned_url(ClientMethod='get_object',Params={ 'Bucket':'bucket-name', 'Key': 'key-name' },ExpiresIn=604800) print(url) |