DEV Community

Cover image for Comprehensive Guide to Installing AWS CLI, Configuring It, and Downloading S3 Buckets Locally
Himanshu Singh Tomar
Himanshu Singh Tomar

Posted on

Comprehensive Guide to Installing AWS CLI, Configuring It, and Downloading S3 Buckets Locally

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

  1. Download the AWS CLI MSI installer from the AWS CLI Installation Page.
  2. Run the installer and follow the on-screen instructions.
  3. Verify the installation by opening Command Prompt and running:
   aws --version
Enter fullscreen mode Exit fullscreen mode

On macOS

  1. Use the curl command to download the AWS CLI installer:
   curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
Enter fullscreen mode Exit fullscreen mode
  1. Install the package:
   sudo installer -pkg AWSCLIV2.pkg -target /
Enter fullscreen mode Exit fullscreen mode
  1. Verify the installation:
   aws --version
Enter fullscreen mode Exit fullscreen mode

On Linux

  1. Use the curl command to download the installer:
   curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Enter fullscreen mode Exit fullscreen mode
  1. Unzip the downloaded file:
   unzip awscliv2.zip
Enter fullscreen mode Exit fullscreen mode
  1. Run the installer:
   sudo ./aws/install
Enter fullscreen mode Exit fullscreen mode
  1. Verify the installation:
   aws --version
Enter fullscreen mode Exit fullscreen mode

Step 2: Configure AWS CLI

  1. Run the following command:
   aws configure
Enter fullscreen mode Exit fullscreen mode
  1. 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, or text.
  2. 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
Enter fullscreen mode Exit fullscreen mode

Example:

To download the pieworks-uploads bucket to your /Users/himanshu/Documents directory:

sudo aws s3 cp s3://uploads /Users/himanshu/Documents --recursive
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

Summary

  1. Install AWS CLI based on your operating system.
  2. Configure AWS CLI with your credentials and region.
  3. Use aws s3 cp or aws 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)