AWS

AWS Copy Files to S3 using AWS-CLI

AWS Copy Files to S3 using AWS-CLI. Amazon S3 is a very fast and reliable storage infrastructure in AWS which is helpful for developers and other services to store data and download them when necessary as private or public.

In this guide you are going to learn how to use the AWS-CLI commands to perform various operation on your S3 bucket in Amazon Web Services.

Choose Best Hosting for your Business

PlatformReviewsPricing
Siteground★★★★★$3.95
Bluehost★★★★★$3.95
Kinsta – Google Cloud★★★★★$30

Prerequisites

Once you have all the prerequisites done, open command prompt or terminal on your local computer and execute the relevant commands.

If you didn’t configure the default region name you will get this error while creating buckets (InvalidLocationConstraint).

Create a new AWS S3 Bucket

You can easily create a new bucket on your S3 using the mb make-bucket command.

aws s3 mb s3://bucket_name

Delete AWS S3 Bucket

You can also easily delete an existing bucket on your S3 using the rb remove-bucket command.

aws s3 rb s3://bucket_name 

You need to use the force option to delete the bucket with all the contents.

aws s3 rb s3://bucket_name --force

List all Buckets in S3

You can list all available buckets in your AWS S3 using the ls command.

aws s3 ls

Copy from Local to Amazon S3

To copy files from local computer to Amazon S3 you can use the cp command.

aws s3 cp filename s3://bucket_name

Copy Multiple Files to Amazon S3

aws s3 cp directory_path s3://bucket_name --recursive

Delete all files inside the bucket

You can use the recursive option to delete all files inside the bucket.

aws s3 rm s3://bucket_name --recursive

Include/Exclude

While copying or deleting you can exclude files using the exclude option and include using the include option also.

aws s3 cp directory_path s3://bucket_name --recursive --exclude "*.log" --include "*.jpg"

The above command is used to exclude and include files while copying.

aws s3 rm s3://bucket_name --recursive --exclude "*.png"

The above command is used to exclude and include files while deleting.

Setup Permissions to files

You can also setup permissions to the files while copying using the acl option with privatepublic-read, and public-read-write values.

aws s3 cp . s3://bucket_name --recursive --acl public-read

The above command uploads all files in the current directory with public read permissions.

Copy only Missing Objects

You can also copy only missing objects in the source and target using the sync option.

aws s3 sync filename s3://bucket_name

While using sync option you can also also use the recursive, exclude, include and acl options.

Cloudbooklet builds a large collection of Linux based guides and tutorials on Cloud platforms like Google Cloud, AWS, Azure, DigitalOcean and more

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.