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.
- An active AWS account.
- Install AWS CLI as mentioned in the official documentation.
- Configure AWS CLI as mentioned here.
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 (
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
aws s3 ls
Copy from Local to Amazon S3
To copy files from local computer to Amazon S3 you can use the
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
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
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
aws s3 sync filename s3://bucket_name
While using sync option you can also also use the