Managing AWS S3 using AWS CLI

AWS S3

Amazon Simple Storage Service (Amazon S3) is an object storage service offering industry-leading scalability, data availability, security, and performance. S3 has 99.999999999% (11 9s) of data durability. You can use S3 for object sto…


This content originally appeared on DEV Community and was authored by Rashwan Lazkani

AWS S3

Amazon Simple Storage Service (Amazon S3) is an object storage service offering industry-leading scalability, data availability, security, and performance. S3 has 99.999999999% (11 9s) of data durability. You can use S3 for object storage, host a website or redirect request.

In this article I will show you how you easily from your local environment can manage your S3 bucket when using the AWS CLI.

Prerequisites

  1. AWS CLI installed - tutorial from AWS of how to install the AWS CLI
  2. Configure AWS CLI - tutorial from AWS of how to configure your AWS CLI

Using AWS CLI with AWS S3

There are multiple commands you can use with S3 and the AWS CLI. The default structure is:

s3 <subcommand> [parameters]

I will show you some commands that you might find useful in your daily work and of course there are plenty more.

Create a Bucket
aws s3 mb s3://mybucket
aws s3 mb s3://mybucket --region eu-north-1
Remove a Bucket
aws s3 rb s3://mybucket
aws s3 rb s3://mybucket --force
Deploy

This will use the default profile in your .aws credentials file

aws s3 sync build/ s3://mybucket

If you want to deploy using a custom profile you can use the following command

aws s3 sync build/ s3://mybucket --profile mybucketapp
ls commands
aws s3 ls
aws s3 ls s3://mybucket
aws s3 ls s3://mybucket --recursive
aws s3 ls s3://mybucket --recursive  --human-readable --summarize
Copy a local file to Bucket
aws s3 cp index.html s3://mybucket
Download a file
aws s3 cp s3://mybucket/index.html <path where you want to download the file to>
Delete file/s

Delete a file from Bucket

aws s3 rm s3://mybucket/index.html

Delete all files from a bucket

aws s3 rm s3://mybucket --recursive
Delete Bucket

Delete an empty Bucket. rb = remove bucket

aws s3 rb s3://mybucket

Delete a Bucket and all it's objects

aws s3 rb s3://mybucket --force
Set bucket as a website
aws s3 website s3://mybucket/ --index-document index.html --error-document error.html

Summary

Hope you found these commands useful. Do you have other commands you use? Please share them in the comments.


This content originally appeared on DEV Community and was authored by Rashwan Lazkani


Print Share Comment Cite Upload Translate Updates
APA

Rashwan Lazkani | Sciencx (2022-07-18T15:20:20+00:00) Managing AWS S3 using AWS CLI. Retrieved from https://www.scien.cx/2022/07/18/managing-aws-s3-using-aws-cli/

MLA
" » Managing AWS S3 using AWS CLI." Rashwan Lazkani | Sciencx - Monday July 18, 2022, https://www.scien.cx/2022/07/18/managing-aws-s3-using-aws-cli/
HARVARD
Rashwan Lazkani | Sciencx Monday July 18, 2022 » Managing AWS S3 using AWS CLI., viewed ,<https://www.scien.cx/2022/07/18/managing-aws-s3-using-aws-cli/>
VANCOUVER
Rashwan Lazkani | Sciencx - » Managing AWS S3 using AWS CLI. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/18/managing-aws-s3-using-aws-cli/
CHICAGO
" » Managing AWS S3 using AWS CLI." Rashwan Lazkani | Sciencx - Accessed . https://www.scien.cx/2022/07/18/managing-aws-s3-using-aws-cli/
IEEE
" » Managing AWS S3 using AWS CLI." Rashwan Lazkani | Sciencx [Online]. Available: https://www.scien.cx/2022/07/18/managing-aws-s3-using-aws-cli/. [Accessed: ]
rf:citation
» Managing AWS S3 using AWS CLI | Rashwan Lazkani | Sciencx | https://www.scien.cx/2022/07/18/managing-aws-s3-using-aws-cli/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.