This is why S3 Bucket Names are unique Globally

S3 Bucket Names are unique Globally
Sharing is Caring:

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 same name even in any other region or accounts until you delete that bucket.

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

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

So let’s start.

What is S3?

Before going into the actual topic I would like to give you a brief introduction about 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 kind of data in our bucket.

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 example below.

Accessible over Rest API :

AWS S3 provides us a way to access bucket and it’s object using REST API.

They looks something like –

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

Basically above path needs to be DNS compliant and no two domain name can be same. So bucket names need to be unique in order to retrieve a bucket and objects using 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 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 an 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 bucket).

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

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

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 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 same bucket in Multiple Environment

Now you will tell me-

Hey !!! , having business name as 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 environment.

You are absolutely right !!

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

I simply prefix Stage name like

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

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

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 issue please add in comment section . We would love to resolve your issue.

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

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

  • Adding a comment on this post on what you liked and what can be improved.
  • Follow Cloudkatha on –
  • Subscribe to our newsletter to get notified each time we post new content.
  • Share this post with your friends and colleagues

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.

Sharing is Caring:

Leave a Reply

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