AWS

S3NoSuchBucket - S3 No Such Bucket

Getting an **S3NoSuchBucket** error means the S3 bucket you're trying to access doesn't exist—the bucket might have been deleted, the name is misspelled, or it's in a different region or AWS account. This client-side error (4xx) happens when AWS validates bucket existence. Most common when bucket names are misspelled, but also appears when buckets don't exist, buckets are deleted, incorrect regions are specified, or buckets are in different AWS accounts.

#Common Causes

  • Identity: IAM policy allows S3 access but bucket doesn't exist. Service Control Policy (SCP) restricts bucket access.
  • Network: VPC endpoint bucket restrictions. Cross-region bucket access.
  • Limits: Bucket name misspelled. Bucket does not exist. Bucket deleted. Incorrect region specified. Bucket in different AWS account.

Solutions

  1. 1Step 1: Diagnose - List all S3 buckets: aws s3 ls. Check if bucket name is in the list. Verify bucket ownership. Check bucket region.
  2. 2Step 2: Diagnose - Check bucket in specific region: aws s3api head-bucket --bucket BUCKET_NAME --region REGION. Verify region is correct. Check if bucket exists in that region.
  3. 3Step 3: Diagnose - Search for similar bucket names: aws s3 ls | grep PARTIAL_NAME. Find correct bucket name. Check for typos.
  4. 4Step 4: Fix - Use correct bucket name: Verify bucket name from list. Check for typos. Use exact bucket name (case-sensitive). Verify bucket ARN if using ARN.
  5. 5Step 5: Fix - Check if bucket was deleted: Review CloudTrail logs: aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteBucket. Or create bucket if needed: aws s3api create-bucket --bucket BUCKET_NAME --region REGION.

</>Code Examples

List All S3 Buckets to Find Correct Name
1#!/bin/bash
2echo "=== All S3 Buckets ==="
3aws s3 ls --output table
4
5# Search for specific bucket
6BUCKET_NAME="my-bucket"
7echo "\n=== Searching for Bucket: ${BUCKET_NAME} ==="
8aws s3 ls | grep -i "${BUCKET_NAME}" || echo "Bucket not found in list"
9
10# Check if exact bucket exists
11echo "\n=== Checking Exact Bucket ==="
12if aws s3api head-bucket --bucket ${BUCKET_NAME} 2>/dev/null; then
13  echo "✓ Bucket ${BUCKET_NAME} exists"
14  
15  # Get bucket details
16  echo "\n=== Bucket Details ==="
17  aws s3api get-bucket-location --bucket ${BUCKET_NAME} --query LocationConstraint --output text
18  aws s3api get-bucket-versioning --bucket ${BUCKET_NAME} --query StatusMap --output table
19else
20  echo "✗ Bucket ${BUCKET_NAME} not found (S3NoSuchBucket)"
21  echo "\nSimilar bucket names:"
22  aws s3 ls | grep -i "${BUCKET_NAME:0:5}" | head -5
23fi
Check S3 Bucket Across Regions
1#!/bin/bash
2BUCKET_NAME="my-bucket"
3
4echo "=== Checking Bucket Across Regions ==="
5REGIONS=("us-east-1" "us-west-2" "eu-west-1" "ap-southeast-1")
6
7for REGION in "${REGIONS[@]}"; do
8  echo "\nChecking region: ${REGION}"
9  
10  # Try to head bucket in this region
11  aws s3api head-bucket \
12    --bucket ${BUCKET_NAME} \
13    --region ${REGION} 2>&1 | head -1
14  
15  if [ $? -eq 0 ]; then
16    echo "✓ Bucket found in ${REGION}"
17    
18    # Get bucket location
19    LOCATION=$(aws s3api get-bucket-location \
20      --bucket ${BUCKET_NAME} \
21      --region ${REGION} \
22      --query LocationConstraint \
23      --output text)
24    echo "Bucket location: ${LOCATION}"
25    break
26  else
27    echo "✗ Bucket not found in ${REGION}"
28  fi
29done
Create S3 Bucket if It Does Not Exist
1#!/bin/bash
2BUCKET_NAME="my-bucket"
3REGION="us-east-1"
4
5echo "=== Checking if Bucket Exists ==="
6if aws s3api head-bucket --bucket ${BUCKET_NAME} 2>/dev/null; then
7  echo "✓ Bucket ${BUCKET_NAME} already exists"
8else
9  echo "✗ Bucket ${BUCKET_NAME} does not exist"
10  echo "\n=== Creating Bucket ==="
11  
12  if [ "${REGION}" = "us-east-1" ]; then
13    # us-east-1 doesn't need LocationConstraint
14    aws s3api create-bucket \
15      --bucket ${BUCKET_NAME} \
16      --region ${REGION}
17  else
18    aws s3api create-bucket \
19      --bucket ${BUCKET_NAME} \
20      --region ${REGION} \
21      --create-bucket-configuration LocationConstraint=${REGION}
22  fi
23  
24  if [ $? -eq 0 ]; then
25    echo "✓ Bucket created successfully"
26    echo "\n=== Verifying Bucket ==="
27    aws s3api head-bucket --bucket ${BUCKET_NAME}
28  else
29    echo "✗ Failed to create bucket"
30    echo "Check bucket name (must be globally unique)"
31  fi
32fi

Related Errors

Provider Information

This error code is specific to AWS services. For more information, refer to the official AWS documentation.

S3NoSuchBucket - S3 No Such Bucket | AWS Error Reference | Error Code Reference