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
- AWS CLI installed - tutorial from AWS of how to install the AWS CLI
- 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.
Top comments (0)