How to Create S3 Bucket in AWS [ 2 Steps]

In this article , We are going to cover How to Create S3 Bucket in AWS, adding and deleting file from s3, enable bucket versioning, disable bucket versioning, remove object from s3 bucket and delete s3 bucket using CLI.

Create S3 Bucket from EC2

Step #1: Create a Role with S3 Full Access

Step #2: Create an EC2 instance and assign the newly created role to it.

Step #3: Login to EC2 Instance using putty.

Step #4: Change to root user. Create a s3 bucket using command

aws s3 mb s3://bucket-name

Step #5: List all the content of bucket using command

aws ls s3://bucket-name

Since our bucket is currently empty, we are not seeing any content.

Step #6: Create a file using touch command and write something inside it using Vi command. Then check the content of file using Cat command.

Step #7: Copy the newly created file to bucket using cp command

aws s3 cp filename.txt bucketpath

Step #8: Enable versioning in bucket using command:

aws s3api put-bucket-versioning --bucket bucket-name --versioning-configuration Status=Enabled

To heck whether versioning got enabled or not.

 aws s3api get-bucket-versioning –bucket bucket-name

Step #9: Make changes in file and check whether versions of file are maintained or not

Checked in GUI and found that both versions of file are present

Step #10: Suspend versioning of s3 bucket through CLI

aws s3api put-bucket-versioning –bucket bucket-name –versioning-configuration Status=Suspended

Step #11: Command to view s3 bucket versioning

aws s3api get-bucket-versioning –bucket bucket-name

Step #12: To Remove s3 Bucket object command

aws s3 rm s3:// bucket-name/object-name

Step #13: To Remove bucket using command

aws s3 rb s3://bucket-name

Step #14: To delete versions of object

aws s3api delete-objects --bucket bucket-name --delete "$(aws s3api list-object-versions --bucket bucket-name | jq -M '{Objects: [.["Versions","DeleteMarkers"][]|select(.Key == "key-value")| {Key:.Key, VersionId : .VersionId}], Quiet: false}')"

Step #15: To delete s3 bucket

aws s3 rb s3://bucket-name --force

Conclusion:

We have covered How to Create S3 Bucket in AWS, adding and deleting file from s3, enable bucket versioning, disable bucket versioning, remove object from s3 bucket and delete s3 bucket using CLI.

Related Articles:

How to Create Ubuntu Instance in AWS [7 Steps]

How to Attach IAM Role to EC2 Instance

How to connect to AWS EC2 Instance using MobaXTerm

How to Enable Password Authentication for AWS EC2

How to Connect EC2 Instance using Putty

How to Transfer files to AWS Instance using WinSCP [2 Steps]

How to Create AWS DocumentDB and Connect [3 steps]

How to Install MySQL 5.7 on Amazon Linux 2

AWS Create Instance from snapshot

AWS Create EC2 Instance from Snapshot

Reference:

AWS Official page

About Rahul Deshpande

I am Rahul Deshpande AWS Certified Solution Architect, Likes to explore new technology stacks and believe in sharing knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link