Downloading objects - Amazon Simple Storage Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Downloading objects

This section explains how to download objects from an Amazon S3 bucket. With Amazon S3, you can store objects in one or more buckets, and each single object can be up to 5 TB in size. Any Amazon S3 object that is not archived is accessible in real time. Archived objects, however, must be restored before they can be downloaded. For information about downloading archived objects, see Downloading archived objects.

You can download a single object by using the Amazon S3 console, Amazon Command Line Interface (Amazon CLI), Amazon SDKs, or Amazon S3 REST API. To download an object from S3 without writing any code or running any commands, use the S3 console. For more information, see Downloading an object.

To download multiple objects, use Amazon CloudShell, the Amazon CLI, or the Amazon SDKs. For more information, see Downloading multiple objects.

If you need to download part of an object, you use extra parameters with the Amazon CLI or REST API to specify only the bytes that you want to download. For more information, see Downloading part of an object.

If you need to download an object that you don't own, ask the object owner to generate a presigned URL that allows you to download the object. For more information, see Downloading an object from another Amazon Web Services account.

When you download objects outside of the Amazon network, data-transfer fees apply. Data transfer within the Amazon network is free within the same Amazon Web Services Region, but you will be charged for any GET requests. For more information about data-transfer costs and data-retrieval charges, see Amazon S3 pricing.

Downloading an object

You can download an object by using the Amazon S3 console, Amazon CLI, Amazon SDKs, or REST API.

This section explains how to use the Amazon S3 console to download an object from an S3 bucket.

Note
  • You can download only one object at a time.

  • If you use the Amazon S3 console to download an object whose key name ends with a period (.), the period is removed from the key name of the downloaded object. To retain the period at the end of the name of the downloaded object, you must use the Amazon Command Line Interface (Amazon CLI), Amazon SDKs, or Amazon S3 REST API.

To download an object from an S3 bucket
  1. Sign in to the Amazon Web Services Management Console and open the Amazon S3 console at https://console.amazonaws.cn/s3/.

  2. In the Buckets list, choose the name of the bucket that you want to download an object from.

  3. You can download an object from an S3 bucket in any of the following ways:

    • Select the check box next to the object, and choose Download. If you want to download the object to a specific folder, on the Actions menu, choose Download as.

    • If you want to download a specific version of the object, turn on Show versions (located next to the search box). Select the check box next to the version of the object that you want, and choose Download. If you want to download the object to a specific folder, on the Actions menu, choose Download as.

The following get-object example command shows how you can use the Amazon CLI to download an object from Amazon S3. This command gets the object folder/my_image from the bucket DOC-EXAMPLE-BUCKET1. The object will be downloaded to a file named my_downloaded_image.

aws s3api get-object --bucket DOC-EXAMPLE-BUCKET1 --key folder/my_image my_downloaded_image

For more information and examples, see get-object in the Amazon CLI Command Reference.

For examples of how to download an object with the Amazon SDKs, see Use GetObject with an Amazon SDK or command line tool.

For general information about using different Amazon SDKs, see Developing with Amazon S3 using the Amazon SDKs, and explorers.

You can use the REST API to retrieve objects from Amazon S3. For more information, see GetObject in the Amazon Simple Storage Service API Reference.

Downloading multiple objects

You can download multiple objects by using Amazon CloudShell, the Amazon CLI, or the Amazon SDKs.

Amazon CloudShell is a browser-based, pre-authenticated shell that you can launch directly from the Amazon Web Services Management Console.

For more information about Amazon CloudShell, see What is CloudShell? in the Amazon CloudShell User Guide.

Important

With Amazon CloudShell, your home directory has storage up to 1GB per Amazon Web Services Region. Therefore you cannot sync buckets with objects totaling over this amount. For more limitations, see Service quotas and restrictions in the Amazon CloudShell User Guide.

To download objects by using Amazon CloudShell
  1. Sign in to the Amazon Web Services Management Console and open the CloudShell console at https://console.amazonaws.cn/cloudshell/.

  2. Run the following command to sync objects in your bucket to CloudShell. The following command syncs objects from the bucket named DOC-EXAMPLE-BUCKET1 and creates a folder named temp in CloudShell. CloudShell syncs your objects to this folder. To use this command, replace the user input placeholders with your own information.

    aws s3 sync s3://DOC-EXAMPLE-BUCKET1 ./temp
    Note

    To perform pattern matching to either exclude or include particular objects, you can use the --exclude "value" and --include "value" parameters with the sync command.

  3. Run the following command to zip your objects in the folder named temp to a file named temp.zip.

    zip temp.zip -r temp/
  4. Choose Actions, and then choose Download file.

  5. Enter the file name temp.zip and then choose Download.

  6. (Optional) Delete the temp.zip file and the objects that are synced to the temp folder in CloudShell. With Amazon CloudShell, you have persistent storage of up to 1 GB for each Amazon Web Services Region.

    You can use the following example command to delete your .zip file and your folder. To use this example command, replace the user input placeholders with your own information.

    rm temp.zip && rm -rf temp/

The following example shows how you can use the Amazon CLI to download all of the files or objects under the specified directory or prefix. This command copies all objects from the bucket DOC-EXAMPLE-BUCKET1 to your current directory. To use this example command, use your bucket name in place of DOC-EXAMPLE-BUCKET1.

aws s3 cp s3://DOC-EXAMPLE-BUCKET1 . --recursive

The following command downloads all of the objects under the prefix logs in the bucket DOC-EXAMPLE-BUCKET1 to your current directory. It also uses the --exclude and --include parameters to copy only objects with the suffix .log. To use this example command, replace the user input placeholders with your own information.

aws s3 cp s3://DOC-EXAMPLE-BUCKET1/logs/ . --recursive --exclude "*" --include "*.log"

For more information and examples, see cp in the Amazon CLI Command Reference.

For examples of how to download all objects in an Amazon S3 bucket with the Amazon SDKs, see Use DownloadDirectory with an Amazon SDK or command line tool.

For general information about using different Amazon SDKs, see Developing with Amazon S3 using the Amazon SDKs, and explorers.

Downloading part of an object

You can download part of an object by using the Amazon CLI or REST API. To do so, you use additional parameters to specify which part of an object that you want to download.

The following example command performs a GET request for a range of bytes in the object named folder/my_data in the bucket named DOC-EXAMPLE-BUCKET1. In the request, the byte range must be prefixed with bytes=. The partial object is downloaded to the output file named my_data_range. To use this example command, replace the user input placeholders with your own information.

aws s3api get-object --bucket DOC-EXAMPLE-BUCKET1 --key folder/my_data --range bytes=0-500 my_data_range

For more information and examples, see get-object in the Amazon CLI Command Reference.

For more information about the HTTP Range header, see RFC 9110 on the RFC Editor website.

Note

Amazon S3 doesn't support retrieving multiple ranges of data in a single GET request.

You can use the partNumber and Range parameters in the REST API to retrieve object parts from Amazon S3. For more information, see GetObject in the Amazon Simple Storage Service API Reference.

Downloading an object from another Amazon Web Services account

You can use a presigned URL to grant others time-limited access to your objects without updating your bucket policy.

The presigned URL can be entered in a browser or used by a program to download an object. The credentials used by the URL are those of the Amazon user who generated the URL. After the URL is created, anyone with the presigned URL can download the corresponding object until the URL expires.

You can use the Amazon S3 console to generate a presigned URL for sharing an object by following these steps. When using the console, the maximum expiration time for a presigned URL is 12 hours from the time of creation.

To generate a presigned URL by using the Amazon S3 console
  1. Sign in to the Amazon Web Services Management Console and open the Amazon S3 console at https://console.amazonaws.cn/s3/.

  2. In the left navigation pane, choose Buckets.

  3. In the Buckets list, choose the name of the bucket that contains the object that you want a presigned URL for.

  4. In the Objects list, select the object that you want to create a presigned URL for.

  5. On the Object actions menu, choose Share with a presigned URL.

  6. Specify how long you want the presigned URL to be valid.

  7. Choose Create presigned URL.

  8. When a confirmation message appears, the URL is automatically copied to your clipboard. You will see a button to copy the presigned URL if you need to copy it again.

  9. To download the object, paste the URL into any browser, and the object will attempt to download.

For more information about presigned URLs and other methods for creating them, see Working with presigned URLs.

Downloading archived objects

To reduce your storage costs for infrequently accessed objects, you can archive those objects. When you archive an object, it is moved into low-cost storage, which means that you can't access it in real time. To download an archived object, you must first restore it.

You can restore archived objects in minutes or hours, depending on the storage class. You can restore an archived object by using the Amazon S3 console, S3 Batch Operations, the Amazon S3 REST API, the Amazon SDKs, and the Amazon Command Line Interface (Amazon CLI).

For instructions, see Restoring an archived object. After you restore the archived object, you can download it.

Troubleshooting downloading objects

Insufficient permissions or incorrect bucket or Amazon Identity and Access Management (IAM) user policies can cause errors when you're trying to download objects from Amazon S3. These problems can often cause Access Denied (403 Forbidden) errors, where Amazon S3 is unable to allow access to a resource.

For common causes of Access Denied (403 Forbidden) errors, see Troubleshoot Access Denied (403 Forbidden) errors in Amazon S3.