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

iam role with s3 full access 1

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

create ec2 instance and attach iam role 2

Step #3: Login to EC2 Instance using putty.

login to ec2 instance using putty 3

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

aws s3 mb s3://bucket-name
create s3 bucket using command line 4

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

aws ls s3://bucket-name
List all the content of bucket using command 5 1

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.

Create a file using touch command 6 1

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

aws s3 cp filename.txt bucketpath
copy the newly created file to s3 bucket 7 1

Step #8: Enable versioning in bucket using command:

aws s3api put-bucket-versioning --bucket bucket-name --versioning-configuration Status=Enabled
Enable versioning in s3 bucket using command 8 1

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

Make changes in file s3 9 1
Make changes in file 9 1 1

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

Checked in s3 GUI 10

Step #10: Suspend versioning of s3 bucket through CLI

aws s3api put-bucket-versioning –bucket bucket-name –versioning-configuration Status=Suspended
Suspend versioning through CLI s3 11

Step #11: Command to view s3 bucket versioning

aws s3api get-bucket-versioning –bucket bucket-name
Command to view s3 bucket versioning 12

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 DevOps Hint

DevOps Hint Founded in 2020 Community Site where you can find about How to Guides, Articles and Troubleshooting Tips for DevOps, SRE, Sysadmins and Developers.

Leave a Comment

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

Share via
Copy link