Download from Amazon S3

Beginner
8 min read
Updated: Nov 2026
5 examples
S3 / AWS CLI

Definition and Usage

Amazon Simple Storage Service (S3) stores objects in buckets. This guide uses the AWS Command Line Interface (CLI) to copy those objects onto your computer.

What does “download from S3” mean?

You authenticate the CLI, then run aws s3 cp (or aws s3 sync) with an s3://bucket/key source and a local destination path. The CLI calls the S3 API and writes files to disk.

When should you use the CLI?

Use it for scripts, large trees, and repeatable transfers. For one-off objects in the console, see Amazon S3 — buckets and uploads. For a CDN in front of a bucket, see CloudFront.

What you will do

Create an access key for a local profile, run aws configure, download one object, copy a whole prefix recursively, then filter by file extension with --exclude / --include.

Credentials in this walkthrough

The examples use IAM user access keys for a quick local setup. Prefer IAM Identity Center (SSO) or short-lived roles when your team supports them.

CLI first, console second.

Once aws configure works, the same patterns scale to sync jobs and CI without clicking through the console.

Treat access keys as secrets.

Never commit keys to source control. Rotate or delete them when you finish learning. Prefer SSO or roles for day-to-day work.

Need TLS for sites next?

After moving data with S3, use ACM for certificates on load balancers, APIs, and CloudFront.

Core Concepts

Terms you will use while downloading:

ConceptMeaning
BucketContainer for objects in a Region
Object keyFull path-like name of a file inside the bucket
s3:// URICLI address form: s3://bucket/prefix/object
aws s3 cpCopy one object or a tree with --recursive
aws s3 syncIncremental copy that skips unchanged files
--exclude / --includeFilters which keys are transferred (order matters)
Access keyIAM user credentials for local CLI profiles (use carefully)
aws configureWrites default profile credentials and Region for the CLI

Prerequisites

Have these ready before you download:

  • An AWS account with permission to read the target bucket (for example s3:GetObject and list on the prefix you need).
  • The AWS CLI installed on your computer (aws --version works).
  • A bucket with sample objects—create one with the S3 console basics guide if needed.

Examples

Authenticate the CLI, then download one file, a full prefix, and a filtered subset.

Example 1 — Create an Access Key

Create an IAM user access key pair in the console for local CLI use (labels can vary slightly over time).

  1. Log in to the AWS Management Console.
  2. Open your account menu (top right), then Security credentials (or IAM → your user → Security credentials).
  3. Under Access keys, choose Create access key and complete the wizard. Store the secret immediately; you cannot view it again later.
  4. You should now have an Access key ID and Secret access key for aws configure.
AWS console security credentials in the account menu
AWS Management Console
Creating a new AWS access key in the console
AWS Management Console
Access key created successfully in the AWS console
AWS Management Console

How It Works

  1. Access keys identify an IAM principal to the AWS API from your laptop.
  2. The secret is shown once—save it offline or in a password manager.
  3. Scope the user to S3 read permissions you actually need.
  4. Prefer SSO for teams—see IAM Identity Center when you outgrow long-lived keys.

Example 2 — Configure the AWS CLI

Open a terminal and store credentials in the default profile.

Terminal
aws configure

Enter your Access key ID, Secret access key, default Region (for example us-east-1), and output format (for example json) when prompted.

Terminal running aws configure
Local terminal

How It Works

  1. aws configure writes values under ~/.aws/ for the default profile.
  2. Region tells the CLI which regional endpoint to prefer for many calls.
  3. Only paste keys on a machine you trust—anyone with the secret can act as that user until you disable it.
  4. After success, aws s3 commands can target your buckets.
Do not share profiles casually.

Shared laptops and screenshots of aws configure output are common ways keys leak.

Example 3 — Download a Single File

Copy one object to a local path (adjust bucket, key, and destination).

Terminal
aws s3 cp s3://your-bucket-name/path/to/image.jpg /path/on/local/machine/
Terminal showing successful download of one image from S3
Local terminal

How It Works

  1. Source is an s3:// URI pointing at one object key.
  2. Destination is a file path or a directory that already exists.
  3. The CLI calls GetObject (and related APIs) using your configured credentials.
  4. Success prints a transfer summary in the terminal when the file lands on disk.

Example 4 — Download All Objects Under a Prefix

Use --recursive to copy every object under the given S3 URI into a local directory.

Terminal
aws s3 cp s3://your-bucket-name/ /path/on/local/machine/ --recursive

For repeated runs where you only want new or changed files, aws s3 sync is often a better fit than a full recursive copy.

Terminal showing recursive download of all objects from an S3 prefix
Local terminal

How It Works

  1. --recursive walks the prefix and copies each object.
  2. Local folders mirror key prefixes under the destination directory.
  3. aws s3 sync skips objects that already match, which saves time on large trees.
  4. Confirm disk space before syncing huge buckets to a laptop.

Example 5 — Download Only Matching Files

With aws s3 cp --recursive, add --exclude and --include filters. This example downloads only files ending in .jpg.

Terminal
aws s3 cp s3://your-bucket-name/ /path/on/local/machine/ --recursive --exclude "*" --include "*.jpg"

Filters are evaluated in order; start from a broad exclude and then add narrower includes, or consult the AWS CLI reference for s3 cp for advanced patterns.

Terminal showing S3 recursive copy with include filter for jpg files
Local terminal

How It Works

  1. --exclude "*" drops everything first.
  2. --include "*.jpg" brings JPEG keys back into the transfer set.
  3. Order matters—later rules override earlier matches for a given key.
  4. Same idea works for uploads when you reverse source and destination—see upload files to S3 with the CLI.

Edge Cases & Pitfalls

Most failures are permissions, wrong Region, or filter order.

iam

Access Denied on cp

The profile principal needs s3:GetObject (and usually list) on the prefix. Bucket policies and explicit denies also block downloads.

region

Wrong default Region

A mismatched profile Region can confuse endpoint behavior. Pass --region or fix aws configure to match the bucket.

path

Local directory missing

Create the destination folder first. Some shells fail when the parent path does not exist.

filter

Include without a broad exclude

Filters are sequential. The usual pattern is exclude everything, then include the patterns you want.

keys

Leaked access keys

If a key appears in git or a screenshot, deactivate it in IAM immediately and create a new one.

sync

Recursive copy every time

For large prefixes you revisit often, prefer aws s3 sync so unchanged objects are skipped.

Key Takeaways

  • Authenticate first: aws configure (or SSO) so the CLI can call S3.
  • aws s3 cp: one object, or a tree with --recursive.
  • aws s3 sync: keep a local folder aligned over time.
  • Filters: --exclude / --include pull only the types you need.

One line: configure the CLI, then aws s3 cp / sync from s3:// to a local path.

Frequently Asked Questions

Use aws s3 cp with the s3:// URI for the object and a local path, for example: aws s3 cp s3://your-bucket-name/path/to/image.jpg /path/on/local/machine/
Use aws s3 cp with the --recursive flag from the bucket or prefix to a local directory, or use aws s3 sync for incremental transfers that skip unchanged files.
aws s3 cp copies the paths you specify; with --recursive it walks the prefix. aws s3 sync compares source and destination and skips files that already match, which is useful for incremental backups.
The CLI needs credentials in some form. Access key ID and secret access key are one option; many teams prefer IAM Identity Center (SSO) or IAM roles instead of long-lived keys for better security.
Check IAM permissions on the principal configured in the CLI, S3 bucket policies, object ownership, and any explicit denies. Also confirm the bucket Region matches the profile default if you rely on regional endpoints.
With aws s3 cp --recursive, filters are evaluated in order. A common pattern is --exclude "*" then --include "*.jpg" so only matching keys are copied.

Next: HTTPS on AWS

After moving data with S3 and the CLI, use ACM to provision certificates for load balancers, APIs, and CloudFront.

AWS Certificate Manager →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful