AWS S3–7 CLI Commands That Will Make Your Life Easier
AWS S3–7 CLI Commands That Will Make Your Life Easier
www.awstutor.io

AWS Storage

AWS S3–7 CLI Commands That Will Make Your Life Easier

S3 offers a simple API, unlimited storage and can work seamlessly with other AWS applications. Here are 7 useful S3 CLI commands.

Manish Manalath
Jan 16 · 4 min read

Amazon Simple Storage Service (Amazon S3) is a storage service that you can use to store all types of data from simple documents to gigabytes of data archives. AWS S3 can be used for a range of use cases such as hosting websites, storing data for mobile applications, big data analytics, etc.

One popular use case of S3 is that you can use it to host websites and small web applications for free. I have recently written an article on how you can host a react web application on S3.

S3 uses a structure similar to directories called ‘Buckets’. An S3 bucket is a storage container with a globally unique name, making it easy to generate download links if you want to share your data with others.

AWS CLI is a command-line tool that you can use to interact with most of the AWS services. With the CLI, developers can quickly execute commands on their terminal that perform the required actions on the AWS platform. If you don’t have an AWS account or the CLI installed, this post will help you.

In this article, we will go through a few useful CLI commands that you can use while working with S3.

CREATE BUCKET

To create a new bucket, use the mb command along with the bucket name.

$ aws s3 mb s3://bucket-name

If the bucket name is not available, you will receive the following error.

Make Bucket failed

If the bucket is created successfully, you will receive the message:

make_bucket:<bucket-name>

LIST BUCKETS

$ aws s3 ls

The AWS CLI will list the bucket you just created. If you don’t see your bucket listed, go into your AWS console and make sure your bucket is created.

UPLOAD FILE

The copy command copies your file to the S3 bucket while retaining the original in your system. The move command, however, removes the local copy and sends it to your S3 bucket.

To copy a file:

$ aws s3 cp <filename> s3://bucket-name

To move a file:

$ aws s3 mv <filename> s3://bucket-name

If the commands are successful, you should receive a message saying:

copy/move : <filename> to s3://bucket-name/<filename>

LIST BUCKET CONTENTS

$ aws s3 ls s3://bucket-name

You should get a list of the files in your bucket along with the size and last updated time.

List contents of a bucket

DOWNLOAD FILE

$ aws s3 cp s3://bucket-name/file <filename>

If the file exists in the bucket and downloaded successfully, you should receive the message:

download: s3://bucket-name/<filename> to <filename>

DELETE FILE

$ aws s3 rm s3://bucket-name/<filename>

If the file exists and is deleted successfully, you should receive the message:

delete:s3://bucket-name/<filename>

DELETE BUCKET

$aws s3 rb s3://bucket-name

If successful, you should see the message:

remove_bucket:bucket-name

BONUS COMMAND (HACK)

If a command issued is not available, AWS CLI will list all available commands. So if you try

$ aws s3 commands

you should get the following message:

S3 CLI commands

SUMMARY


Hope this article helped you get familiar with S3 and the AWS CLI in general. If you have any questions, let me know in the comments. You can also signup for my newsletter to receive a summary of articles once a week.

AWS Tutor

Articles, How-Tos and Use Cases on AWS Tools and Services

Manish Manalath

Written by

10 years as a Digital Nomad. Writes on Tech (http://awstutor.io) and Productivity. Connect with me on Linkedin (linkedin.com/in/manishmshiva)

AWS Tutor

AWS Tutor

Articles, How-Tos and Use Cases on AWS Tools and Services

More From Medium

More from AWS Tutor

More on Programming from AWS Tutor

More on AWS from AWS Tutor

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade