Generating Expiring URLs for S3 Objects

You have private data that you would like to share with someone, but you don’t want to make it widely available.

Use Query String Authentication (QSA) to generate an expiring URL to your data in S3.

One neat feature of S3 is the ability to generate self-expiring URLs pointing to data in S3. This allows you to share private data in S3 without changing the permissions of the object. It also means that you can control how long the URL you pass on to your collaborator will work. You can have it expire in 5 seconds, 5 days, 5 months, or any other time period that seems appropriate. The example below shows an interactive session that creates a new, private object in S3, generates a URL that expires in 30 seconds, retrieves the object data, waits 30 seconds, and then attempts to retrieve the data again to show that access is, in fact, denied.