Amazon S3 expiring URLs with Boto

Posted: August 1st, 2011 | Author: | Filed under: Python | 5 Comments »

This is a short post. I spent too long working this out so hopefully this post will help a future Google search.

If you’re using the Boto python wrapper for the Amazon S3 service, you can quickly generate temporary URLs for your private files.

1
2
3
4
from boto.s3.connection import S3Connection
 
s3 = S3Connection('YOUR_KEY', 'YOUR_SECRET', is_secure=False)
url = s3.generate_url(60, 'GET', bucket='YOUR_BUCKET', key='YOUR_FILE_KEY', force_http=True)

This will give you a URL to your private file on S3 that will only work for 60 seconds. It will look something like this:


http://mycoolbucket.s3.amazonaws.com/myfile.jpg?

Signature=ABC123DEF456&
Expires=1312216031&
AWSAccessKeyId=ABCDEFGHIJKLMNOP
5 Comments »
  • Reid Savage

    If this works like it seems, you have helped a million.

    • Anonymous

      hehe, I should hope so – I’ve been using it for over a year!

  • http://thangavigneshraja.blogspot.com/ Thanga Vignesh Raja T

    its working fine :)

  • Drew Verlee

    I was close to finding a solution reading the docs but this put it together for me. Thanks!

  • Nicholas Polet

    Lovely. Just lovely :)