Creating S3 Bucket Using AWS CLI

AWS provides tools for developing and managing applications on AWS. There are tools like CLI, SDK, Terraform, Cloud formations if you want to automate cloud processes.

In this article, I will show you how to access the features of Amazon Simple Storage Service (Amazon S3) using the AWS Command Line Interface (AWS CLI). The AWS CLI provides two tiers of commands for accessing Amazon S3:

Creating Buckets and Uploading data to S3

First, check your AWS Region using this command.

aws configure get region

If you want to change your AWS Region, you can use this command. You can choose the AWS Region where you want the bucket to reside by changing ‘ap-southeast-2’.

aws configure set region ap-southeast-2

After that, you can list all s3 buckets that you have in your account.

aws s3 ls

To create a bucket, you can use ‘mb’ command. Throughout this guide, I’ll use “my-bucket” as an example name, but you are free to change this to something else. For Bucket naming rule, you can visit this guide.

aws s3 mb s3://my-bucket

Let’s upload a file to your new S3 bucket. I use filename.txt and upload it to “my-bucket”.

aws s3 cp filename.txt s3://my-bucket

Then, list all files on bucket.

aws s3 ls s3://my-bucket

How to download a file from S3 bucket via AWS CLI? Well, you have to generate a pre-signed URL for an Amazon S3 object. This allows anyone who receives the pre-signed URL to retrieve the S3 object with an HTTP GET request. I download filename.txt using this command.

aws s3 presign s3://my-bucket/filename.txt

Say, you want to delete an object on a bucket, use ‘rm’ command.

aws s3 rm s3://my-bucket/filename.txt

That’s it. Now, you can use the AWS CLI to access your S3 bucket. Here are some resources if you want to deep dive into AWS CLI.

Please feel free to reach out to me if you have any questions.