Skip to main content

detect_bucket_region

Function detect_bucket_region 

Source
pub fn detect_bucket_region(bucket: &str) -> String
Expand description

Detect the AWS region for bucket by sending an HTTP HEAD request to <bucket>.s3.amazonaws.com:80 and reading the x-amz-bucket-region response header.

S3 includes this header even in 301/403 responses. A raw TCP connection is used because HTTP clients typically surface non-2xx as errors and discard the response headers.

Falls back to "eu-central-1" on any error. Callers are responsible for caching results to avoid repeated HEAD requests for the same bucket (see RegionCache).