A Step-by-Step Guide to Downloading Files from Amazon S3 Using Presigned URLs

Ramkrushna Maheshwar
2 min readJul 7, 2023

--

Amazon Simple Storage Service (S3) is a popular cloud storage solution that provides secure and scalable object storage. One powerful feature of S3 is the ability to generate presigned URLs, which grant temporary access to specific files. This article will guide you through the process of downloading files from an S3 bucket using presigned URLs, allowing you to securely retrieve files with ease.

Step 1: Obtaining the Presigned URL

To initiate the file download, you need to generate a presigned URL. This URL includes the necessary authorization parameters and an expiration time. Using the AWS Command Line Interface (CLI), you can execute the following command:

aws s3 presign s3://bucket-name/file-key --expires-in 3600

Replace bucket-name with the name of your S3 bucket and file-key with the specific file's key you wish to download. The --expires-in parameter sets the expiration time for the presigned URL (in this example, 3600 seconds or one hour).

Step 2: Downloading the File

With the presigned URL in hand, you can proceed to download the file. There are multiple methods available for downloading, such as using a web browser or an HTTP client like curl. Let's explore the curl command-line option:

curl -o "output-file-name" "presigned-url"

By replacing "output-file-name" with the desired name you want to assign to the downloaded file and "presigned-url" with the actual presigned URL, you can initiate the download. For instance:

curl -o "my_file.txt" "presigned-url"

The file will be saved as “my_file.txt” in the current directory.

Step 3: Customizing File Name and Location

To save the downloaded file with a specific name or in a different location, adjust the -o parameter in the curl command accordingly. You can specify a complete file path to save the file in a specific directory:

curl -o "/path/to/destination/file-name.extension" "presigned-url"

Ensure that the directory exists before executing the command.

Conclusion:

Downloading files from an Amazon S3 bucket using presigned URLs is a secure and efficient method to retrieve specific files for a limited period. With the provided step-by-step guide, you can generate a presigned URL and effortlessly download files using the curl command or other HTTP clients. Whether you need to automate downloads or manually retrieve files, the flexibility and simplicity of presigned URLs make them an excellent choice for securely accessing your S3 resources.

--

--