How to Install AWS CLI on All Operating Systems, Configure It, and Download an S3 Bucket Locally
The AWS Command Line Interface (CLI) is a powerful tool for managing AWS services from your terminal. This guide walks you through installing the AWS CLI on Windows, macOS, and Linux, configuring it, and downloading an entire S3 bucket to your local machine.
Step 1: Install AWS CLI
On Windows
- Download the AWS CLI MSI installer from the AWS CLI Installation Page.
- Run the installer and follow the on-screen instructions.
- Verify the installation by opening Command Prompt and running:
aws --version
On macOS
- Use the
curl
command to download the AWS CLI installer:
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
- Install the package:
sudo installer -pkg AWSCLIV2.pkg -target /
- Verify the installation:
aws --version
On Linux
- Use the
curl
command to download the installer:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- Unzip the downloaded file:
unzip awscliv2.zip
- Run the installer:
sudo ./aws/install
- Verify the installation:
aws --version
Step 2: Configure AWS CLI
- Run the following command:
aws configure
-
Enter the required details when prompted:
- AWS Access Key ID: Obtain this from the AWS Management Console.
- AWS Secret Access Key: Corresponding secret for your Access Key ID.
-
Default Region Name: Example:
us-east-1
. -
Default Output Format: Use
json
,yaml
, ortext
.
-
The
aws configure
command creates two configuration files:-
~/.aws/credentials
(contains access keys). -
~/.aws/config
(contains region and output format).
-
Step 3: Download an S3 Bucket Locally
Command to Download the Entire Bucket
Use the following command to download all files from your S3 bucket:
sudo aws s3 cp s3://<bucket_name> <local_destination> --recursive
Example:
To download the pieworks-uploads
bucket to your /Users/himanshu/Documents
directory:
sudo aws s3 cp s3://uploads /Users/himanshu/Documents --recursive
Explanation:
-
s3://<bucket_name>
: Replace<bucket_name>
with your S3 bucket name. -
<local_destination>
: Replace with the local directory where you want to download the files. -
--recursive
: Ensures all files and subfolders are copied.
Verify the Download:
Check your local destination directory to confirm all files have been downloaded.
ls /Users/himanshu/Documents
Optional: Syncing S3 Bucket Changes
To keep your local folder in sync with the S3 bucket, use:
aws s3 sync s3://<bucket_name> <local_destination>
Summary
- Install AWS CLI based on your operating system.
- Configure AWS CLI with your credentials and region.
- Use
aws s3 cp
oraws s3 sync
to download your S3 bucket locally.
This process makes it easy to manage and retrieve your S3 data directly from the command line. Happy downloading!
Top comments (0)