iam-veeramalla / python-for-devops

Learn Python from DevOps Engineer point of you.
MIT License
2.65k stars 5.28k forks source link

Resolved the IllegalLocationConstrationException while creating Bucket in us-ease-1 region #45

Open anujkp-97 opened 5 months ago

anujkp-97 commented 5 months ago

Creating S3 bucket using Boto3

I was creating an S3 bucket but, Exception IllegalLocationConstrationException. By default S3 bucket was created in US-east-1 region. To solve this Exception, I provided the location to the bucket ap-south-1 and s3 bucket created successfully.

Here is the code:

import boto3

client = boto3.client('s3')

response = client.create_bucket(

Bucket='<your-bucket-name>',
CreateBucketConfiguration={'LocationConstraint': 'ap-south-1'}

)