Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 18, 2022 03:20 pm GMT

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 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://mybucketaws s3 mb s3://mybucket --region eu-north-1
Remove a Bucket
aws s3 rb s3://mybucketaws 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 lsaws s3 ls s3://mybucketaws s3 ls s3://mybucket --recursiveaws 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.


Original Link: https://dev.to/rashwanlazkani/managing-aws-s3-using-aws-cli-3047

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To