How can I check that a AWS S3 bucket exists?


Simple question here? …

How can I check with boto that a AWS bucket exists? … preferably by providing the path? …

here is the approach I feel like taking:

In the code above I am interested to find if a bucket exists amongst the buckets that this AWS Account owns …

IS there a better way to find out if a bucket exists? How would I implement a better way?



You could just try and load the bucket (as you are doing now). By default the method is set to validate if the bucket exists.

You could also just try to “lookup” the bucket. The method will raise an S3ResponseError.

Ether way, you’ll have to make an API call so I think you’re left to personal preference here (whether you like dealing with exceptions, or simply checking for None).

So you have a couple of options here:


Leave a Reply