HumanSignal/label-studio · error · ValidationError

Cannot find bucket {bucket_name} in S3

Error message

Cannot find bucket {bucket_name} in S3

What it means

In S3StorageSerializerMixin.validate(), a ClientError with code NoSuchBucket or HTTP 404 from validate_connection() is converted to 'Cannot find bucket {bucket_name} in S3'. The credentials worked but the named bucket does not exist in that region/account, or the endpoint points at the wrong S3-compatible service.

Source

Thrown at label_studio/io_storages/s3/serializers.py:69

        try:
            storage.validate_connection()
        except ParamValidationError:
            raise ValidationError('Wrong credentials for S3 {bucket_name}'.format(bucket_name=storage.bucket))
        except ClientError as e:
            if (
                e.response.get('Error').get('Code') in ['SignatureDoesNotMatch', '403']
                or e.response.get('ResponseMetadata').get('HTTPStatusCode') == 403
            ):
                raise ValidationError(
                    'Cannot connect to S3 {bucket_name} with specified AWS credentials'.format(
                        bucket_name=storage.bucket
                    )
                )
            if (
                e.response.get('Error').get('Code') in ['NoSuchBucket', '404']
                or e.response.get('ResponseMetadata').get('HTTPStatusCode') == 404
            ):
                raise ValidationError('Cannot find bucket {bucket_name} in S3'.format(bucket_name=storage.bucket))
        except TypeError as e:
            logger.info(f'It seems access keys are incorrect: {e}', exc_info=True)
            raise ValidationError('It seems access keys are incorrect')
        except KeyError:
            raise ValidationError(f'{storage.url_scheme}://{storage.bucket}/{storage.prefix} not found.')
        return data


class S3ImportStorageSerializer(S3StorageSerializerMixin, ImportStorageSerializer):
    type = StorageTypeField(default=os.path.basename(os.path.dirname(__file__)))
    presign = serializers.BooleanField(required=False, default=True)

    def validate_s3_endpoint(self, value):
        if value and settings.SSRF_PROTECTION_ENABLED:
            validate_url_for_ssrf(value, block_local_urls=True)
        return value

    class Meta:

View on GitHub (pinned to 0b49e9b539)

Solutions

  1. Confirm the bucket exists: aws s3 ls | grep <bucket> (and in the right region).
  2. Fix the bucket name or region_name in the storage payload.
  3. If using a custom s3_endpoint, verify the S3-compatible server actually contains that bucket.
  4. Recreate the bucket if it was deleted.

Example fix

// before
{"bucket": "my-bucket-prod"}  // bucket is actually my-bucket-prod-eu

// after
{"bucket": "my-bucket-prod-eu", "region_name": "eu-west-1"}
Defensive patterns

Strategy: validation

Validate before calling

import boto3
from botocore.exceptions import ClientError

def bucket_exists(bucket: str, region: str) -> bool:
    s3 = boto3.client('s3', region_name=region)
    try:
        s3.head_bucket(Bucket=bucket)
        return True
    except ClientError as e:
        code = int(e.response.get('ResponseMetadata', {}).get('HTTPStatusCode', 0))
        if code == 404:
            return False
        raise

assert bucket_exists('my-bucket', 'us-east-1'), 'Bucket does not exist in this region/account'

Type guard

def bucket_field_is_name(value) -> bool:
    return isinstance(value, str) and value.islower() and '/' not in value

Try / catch

try:
    serializer.is_valid(raise_exception=True)
except ValidationError as e:
    if 'Cannot find bucket' in str(e.detail):
        # 404/NoSuchBucket: verify bucket name, region and endpoint

Prevention

When it happens

Trigger: Storage create/update where client.head_bucket / list_objects_v2 returns 404/NoSuchBucket — misspelled bucket, bucket in different region than the endpoint, or deleted bucket.

Common situations: Typo in bucket name; using an endpoint (e.g. custom s3_endpoint for MinIO) that hosts a different namespace; bucket deleted or never created; cross-region access where region_name doesn't match the bucket.

Related errors


AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29). Data as JSON: /api/errors/3d321de49e1ae648. Report an issue: GitHub.