How to Download AWS S3 Content Using AWS CLI on a Mac Machine

  • 4.7/5
  • 1242
  • Sep 23, 2024

Here's a step-by-step guide to setting up and using the AWS CLI to download files from S3.

1) Install AWS CLI on Your Mac

To start, ensure that you have Homebrew installed on your Mac. Homebrew is a package manager that simplifies the installation of software. If you don't have Homebrew installed, you can do so by running this command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once Homebrew is installed, follow these steps:

Update Homebrew to make sure you have the latest packages:

% brew update

Install AWS CLI using Homebrew:

% brew install awscli

After installation, verify that AWS CLI is correctly installed by checking its version:

aws --version

This command should return the version of AWS CLI installed on your system.

2) Configure AWS CLI with Your Credentials

To interact with AWS services, you'll need to configure your AWS CLI with your access keys (Access Key ID and Secret Access Key). Follow these steps to generate your access keys:

2.1) Log in to the AWS Console.

2.2) Click on your username (top-right corner) and select Security Credentials from the dropdown menu.

2.3) In the Access Keys section, click Create New Access Key to generate an Access Key ID and Secret Access Key. Save these keys securely.

Next, configure AWS CLI with these credentials:

Open or create the credentials file at ~/.aws/credentials. You can do this by running the following command:

nano ~/.aws/credentials

Add your Access Key ID and Secret Access Key under the [default] profile:

[default]
aws_access_key_id=<your_access_key_id>
aws_secret_access_key=<your_secret_access_key>

Replace <your_access_key_id> and <your_secret_access_key> with your actual keys.

Save and close the file.

3) Download Content from AWS S3 to Your Mac

Now that your AWS CLI is configured, you can use it to download files from an S3 bucket. The following command allows you to copy files from an S3 bucket to your local machine.

Use the aws s3 cp command with the --recursive flag to download all contents from a specific bucket:

aws s3 cp s3://<bucket-name>/ ~/Desktop --recursive

Replace <bucket-name> with the name of your S3 bucket.

~/Desktop is the destination folder on your local machine where the content will be downloaded.

This command will recursively download all objects from the specified S3 bucket to your desktop.

Index
Create and Run a React app and JSX Basics

14 min

How to Download AWS S3 Content Using AWS CLI on a Mac Machine

2 min

Load Testing using Locust.io (Open-source)

2 min

How to create a Multi-Module Project in Maven

2 min

Building RESTful APIs with Node.js, Express & MongoDB

14 min

Docker commands every developer should know

13 min

AWS S3 integration with Spring Boot (AWS S3 + Spring Boot)

14 min