AWS CLI Upload / Copy Folders with Files to S3 Bucket

In this tutorial, we'll learn how to upload/copy folders with files to the S3 bucket. Let's get started:

Table of Contents

  1. Install AWS CLI
  2. Copy Folders & Files
  3. Public Access Permission

Install AWS CLI

The AWS Command Line Interface (AWS CLI) is a unified tool to manage your AWS services. First, you have to install AWS CLI on your machine. After installation, you can run this command to check whether it is installed correctly or not:

aws --version

Copy Folders & Files

It is very easy to upload folders with files to S3 using, aws s3 cp command. It will require the --recursive parameter to copy multiple files:

aws s3 cp /PATH/DIR s3://BUCKET_NAME –recursive

You can also upload to a specific folder of S3:

aws s3 cp /PATH/DIR s3://BUCKET_NAME/DIR –recursive

An example:

aws s3 cp /var/www/shouts.dev/uploads s3://shouts/uploads

Public Access Permission

By default, AWS CLI uploads files in private mode. We can set the Access Control List (ACL) while copying an object. We just need to add --acl public-read option at the end of the command:

aws s3 cp /PATH/DIR s3://BUCKET_NAME/DIR –recursive --acl public-read

Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.