Download a Folder from AWS S3

askyt

Avnish

Posted on March 29, 2024

Download a Folder from AWS S3

Downloading a folder or its contents from AWS S3 to your local system is a common task that can be accomplished using the AWS Command Line Interface (CLI). The AWS CLI provides a convenient way to interact with AWS services, including S3, from the command line. Here's a step-by-step guide on how to download a folder from S3 using the AWS CLI:

1. Install the AWS CLI

Before you start, ensure that the AWS CLI is installed on your system. You can install it using either easy_install or pip, which are Python package managers. If you don't have the AWS CLI installed yet, you can install it by running one of the following commands in your terminal or command prompt:

  • Using easy_install:
  sudo easy_install awscli
Enter fullscreen mode Exit fullscreen mode
  • Using pip:
  sudo pip install awscli
Enter fullscreen mode Exit fullscreen mode

2. Configure the AWS CLI

After installing the AWS CLI, you need to configure it with your AWS credentials and default region. You can do this by running the following command and following the prompts:

aws configure
Enter fullscreen mode Exit fullscreen mode

You will be asked to enter your AWS Access Key ID, Secret Access Key, default region name, and output format. These credentials are used to authenticate your requests to AWS.

3. Download a Folder from S3

To download a folder from S3 to your local system, you can use the aws s3 cp command with the --recursive option. This option allows the command to copy files recursively from the source directory in S3 to the destination directory on your local system. Here's the syntax for the command:

aws s3 cp s3://BUCKETNAME/PATH/TO/FOLDER LocalFolderName --recursive
Enter fullscreen mode Exit fullscreen mode
  • BUCKETNAME is the name of your S3 bucket.
  • PATH/TO/FOLDER is the path to the folder within the bucket that you want to download.
  • LocalFolderName is the name of the local folder where you want to download the contents. If this folder doesn't exist, the AWS CLI will create it for you.

For example, to download a folder named myfolder from a bucket named mybucket to a local folder named MyLocalFolder, you would run:

aws s3 cp s3://mybucket/myfolder MyLocalFolder --recursive
Enter fullscreen mode Exit fullscreen mode

This command downloads all files and subfolders within myfolder from the S3 bucket mybucket to the local folder MyLocalFolder.

Remember, this operation is a one-way sync from S3 to your local system. It will not delete any existing files in your local directory unless you specify additional options like --delete. Also, it won't change or delete any files on S3.

💖 💪 🙅 🚩
askyt
Avnish

Posted on March 29, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related