This is why S3 Bucket Names are unique Globally

S3 Bucket Names are unique Globally

S3 Bucket Names are unique Globally?

You might be surprised to know that, once you create an S3 bucket named “my-bucket“, you or anyone else can not create a bucket with the same name even in any other region or account until you delete that bucket.

This simply means that the S3 bucket name is unique globally and the namespace is shared by all AWS accounts.

In this post, you will know a few reasons behind this. You will also learn how to design your bucket names to overcome this unique requirement.

So let’s start.

Don’t want to miss any posts from us? join us on our Facebook group, and follow us on Facebook, Twitter, LinkedIn, and Instagram. You can also subscribe to our newsletter below to not miss any updates from us.

What is S3?

Before going into the actual topic I would like to give you a brief introduction to AWS S3.

As per AWS, Simple Storage Service is storage for the internet. It is highly scalable, reliable, fast and inexpensive data storage provided by AWS.

It allows you to store and retrieve any amount of data, at any time, from anywhere on the web.

In S3, we create buckets and then we store all kinds of data in our buckets.

S3 Bucket Names are unique Globally

As we said earlier, S3 bucket names are unique globally

But the question is why?

Well, S3 was designed this way to keep the namespace global and accordingly keeping that uniqueness in mind other features of S3 were defined.

In other words, If I frame the above sentence, uniqueness is to support some of the features provided by AWS S3.

Let’s take some examples below.

Accessible over Rest API :

AWS S3 provides us with a way to access the bucket and its object using REST API.

They look something like –

  • bucketname.s3.region.amazonaws.com (Virtual hosted style addressing) or
  • s3.region.amazonaws.com/bucketname (path style addressing)

Basically, the above path needs to be DNS compliant and no two domain names can be the same. So bucket names need to be unique in order to retrieve a bucket and objects using the REST endpoint.

Now you may have a question which I had.

Why can’t it be tagged to an AccountId so that it’s global on the account level?

Well, for a publicly accessible endpoint, this poses a major security concern/risk.

So, I am sure, the engineers and architects at AWS thought through all possible ways and decided on keeping the namespace global to keep things simple and straightforward.

Allows Object Access using Bucket and Key only

AWS S3 is object storage and follows a flat data storage structure (Without folders). To fetch any object, all you need is the bucket name and key(Version ID as well in case versioning is enabled on the bucket).

Related: How to Enable Versioning on an S3 Bucket

Please note that no region is needed to retrieve an object. Also, the get object will not only work in the region in which your s3 bucket exists. Rather you can make the request from any region and S3 is able to redirect to the correct bucket incorrect region.

If bucket names were not unique, S3 wouldn’t have been able to redirect the request without ambiguity to the correct region.

Related: S3 is Regional or Global?

How to Overcome the Uniqueness of S3 Bucket Name

When we know that bucket name is global and this is not going to change anytime soon(That’s my thought although).

So, let’s get rid of the fear that “What if the bucket name is already taken”.

Well, to avoid this the best thing that I do is to prefix my bucket with something related to my business.

for example- cloudkatha-website-bucket

If I create a bucket with the name website-bucket, It sounds too generic and might be taken. But your business name is unique to you and adding a prefix helps to make your bucket unique as well as relevant.

How to create the same bucket in Multiple Environments

Now you will tell me-

Hey !!! , having a business name as a prefix is good for me till I have a single environment.

But what to do while going to multi-account – test and prod. My code is going to need the same bucket in all environments.

You are absolutely right !!

But worry not my friend, I will tell you what I do 🙂

I simply prefix Stage names like

  • dev-cloudkatha-website-bucket
  • test-cloudkatha-website-bucket
  • prod-cloudkatha-website-bucket

I am sure it will make more sense in a multi-account environment scenario. While accessing the bucket we access {Stage}-cloudkatha-website-bucket and as per the environment we always get the correct bucket name.

Related: How to Create Multiple S3 Bucket using Terraform

Conclusion:

In this post, we discussed why s3 bucket names are unique globally and how to overcome the uniqueness across accounts/ environments.

I hope this post was useful to you. In case of any issues please add them in the comment section. We would love to resolve your issue.

Please feel free to let us know what you think regarding the S3 bucket’s uniqueness.

If you liked my post, Please motivate me and help me get better by –

Please share your feedback and help us get better with time 🙂

Also Read:

Disclaimer: This post is my thought on the issue and It can differ from AWS official. I have written it as per my understanding.

Leave a Reply

Your email address will not be published. Required fields are marked *