CodexBloom - Programming Q&A Platform

AWS S3 Pre-Signed URL guide with Expiration optimization guide as Expected

πŸ‘€ Views: 12 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-11
AWS S3 boto3 presigned-urls Python

I'm collaborating on a project where I've been banging my head against this for hours... I'm working on a personal project and I'm working with an scenario while generating pre-signed URLs for objects in my S3 bucket using the AWS SDK for Python (boto3). I generated a pre-signed URL with a 1-minute expiration, but when I try to access it after 30 seconds, it still seems to be valid, and I can download the object. Here’s the code snippet I am using: ```python import boto3 s3_client = boto3.client('s3') bucket_name = 'my-bucket' object_key = 'my-object.txt' # Generate a pre-signed URL that expires in 60 seconds url = s3_client.generate_presigned_url( 'get_object', Params={'Bucket': bucket_name, 'Key': object_key}, ExpiresIn=60 ) print(f'Pre-signed URL: {url}') ``` I expected the URL to be invalid after 60 seconds, but it appears to be accessible even after this period. I have also checked the AWS IAM policy and confirmed that the permissions are correctly set for the S3 actions. Is there something I might be overlooking? Could there be any caching mechanism or delay in expiration that I’m not aware of? I’ve tried different expiration values, but the behavior remains the same. Any insights would be greatly appreciated! My development environment is Windows. I'd really appreciate any guidance on this.