For example, I have this code:
import boto3
s3 = boto3.resource(\'s3\')
bucket = s3.Bucket(\'my-bucket-name\')
# Does it exist???
you can use conn.get_bucket
from boto.s3.connection import S3Connection
from boto.exception import S3ResponseError
conn = S3Connection(aws_access_key, aws_secret_key)
try:
bucket = conn.get_bucket(unique_bucket_name, validate=True)
except S3ResponseError:
bucket = conn.create_bucket(unique_bucket_name)
quoting the documentation at http://boto.readthedocs.org/en/latest/s3_tut.html
As of Boto v2.25.0, this now performs a HEAD request (less expensive but worse error messages).