skip to Main Content

I have uploaded an object with the

 client = boto3.client('s3', aws_access_key_id=AWS_ACCESS_KEY_ID,
                                      aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
 response = client.put_object(
                    Bucket=BUCKET_NAME, Body=in_mem_file.getvalue(), Key=str(img_name))

and I’m generating the URL by

url = client.generate_presigned_url('get_object',  Params={
                                                'Bucket': BUCKET_NAME, 'Key': str(img_name)}, ExpiresIn=518400)

I need to generate the URL without expiring in some cases. Is it possible to generate url without expiring in s3 bucket?

2

Answers


  1. I need to generate the URL without expiring in some cases

    Its not possible. If you don’t want to regenerate links every 7 days, then you have to look at other solutions for sharing S3 files. Often CloudFront with S3 is used. Otherwise, you need fully custom solution tailored to your specific need.

    Login or Signup to reply.
  2. If the object is public, it has a permanent url of the form:

    def get_object_url(region, bucket, object_key)
        return f"https://{bucket}.s3.{region}.amazonaws.com/{object_key}"
    

    Otherwise, you cannot have a permanent link.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search