3

I want generate S3 object URL with no expiration.

My S3 bucket and objects are private as i don't want it to set public.

I tried generating pr_signed url using lambda function but it only validates for 7 days.

Help if anybody knows. Thanks in Advance.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
kalyani_jamunkar
  • 582
  • 1
  • 13
  • 33
  • There is a contradiction in what you are saying, because an object with a URL that does not expire is -- for all practical purposes -- the same thing as a publicly-accessible object. – Michael - sqlbot Apr 10 '19 at 18:54

1 Answers1

1

Yes it has max 604800 seconds(7 days) max to exipre..

But

If You have to make public read for ACL and it will be given non expiring url...

obj = s3.bucket(ENV['S3_BUCKET_NAME']).object(object_name)
obj.write(:file => image_location)
obj.acl = :public_read
obj.public_url.to_s

Or you can use scheduler in cloud watch that will run on or before 604800 secs and renew the expiration...

Write a lambda with this

url = s3.generate_presigned_url(
    ClientMethod='get_object',
    Params={
        'Bucket': 'bucket-name',
        'Key': 'key-name'
    },
    ExpiresIn=604800
)

and run it in cloud watch scheduler on or before 7 days(10080)

aws events put-rule --schedule-expression "rate(10079 minute)" --name bef7day
Rajarshi Das
  • 11,778
  • 6
  • 46
  • 74