import boto3 s3 = boto3.client('s3') try: s3.head_bucket(Bucket='your-bucket-name') except botocore.exceptions.ClientError as e: if e.response['Error']['Code'] == '404': print("The specified bucket does not exist") else: raise