I tried to access an Amazon Simple Storage Service (Amazon S3) bucket in a different AWS Region and received the "IllegalLocationConstraintException" error.
Short description
You can't access an Amazon S3 bucket from a Region that's different from the bucket's Region. To access the S3 bucket, you must update your API or AWS SDK to be in the same Region as the bucket. For more information about the IllegalLocationConstraintException error, see List of error codes.
Resolution
Use the following troubleshooting steps to get the bucket's Region and update your Amazon S3 endpoints to the correct Region.
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
Confirm the Amazon S3 bucket Region
To confirm the S3 bucket Region, you can use the Amazon S3 console or the AWS CLI.
Amazon S3 console
Complete the following steps:
- Open the Amazon S3 console, and then navigate to your S3 bucket.
- Choose the Properties tab.
- In Bucket overview, note the AWS Region for you bucket.
AWS CLI
Run the following get-bucket-location command:
aws s3api get-bucket-location --bucket BUCKET_NAME
Note: Replace BUCKET_NAME with your S3 bucket name.
Example output:
{
"LocationConstraint": "us-west-2"
}
Note: If the LocationConstraint request parameter is null or empty, then the bucket is in the us-east-1 Region.
Update your API or AWS SDK Region configuration
Complete the following steps to update your API or AWS SDK configuration to the correct Region.
AWS CLI
Run the following ls command and add the --region parameter:
aws s3 ls s3://BUCKET_NAME --region YOUR_REGION
Note: Replace BUCKET_NAME with your S3 bucket name and YOUR_REGION with your Region.
AWS SDK
If you use the AWS SDK, then update your configuration to specify the correct Region.
Example AWS SDK for Python (Boto3) configuration:
import boto3
s3 = boto3.client('s3', region_name='YOUR-REGION')
response = s3.list_objects_v2(Bucket='BUCKET_NAME')
print(response)
Note: Replace YOUR_REGION with your Region and BUCKET_NAME with your bucket name.IllegalLocationConstraintException