Location constraint exception while trying to access bucket from aws ec2 client

非 Y 不嫁゛ 提交于 2019-12-06 16:29:41

In your example above:

s3Client.setRegion(Region.getRegion(Regions.AP_SOUTH_1));
// Region apsouth1 = Region.getRegion(Regions.ap-south-1);                  //   s3Client.setRegion(apsouth1);                                                                  //  s3Client.setRegion(Region.getRegion(Regions.ap-south-1));
//s3Client.create_bucket(bucket, CreateBucketConfiguration={'LocationConstraint': 'ap-northeast-2'})

Both "region" and "LocationConstraint" should match. If you want to create the bucket in "ap-south-1" then both should be set to that value.

The error you received was due to the two values not matching, in other words you connected to one region (likely ap-south-1), and then tried to create a bucket which is intended to exist in another region (ap-northeast-2).

By excluding "LocationConstraint", the location where the bucket is created is entirely based on the "Region" which you are connected to. By using "LocationConstraint" you can ensure you are not trying to create the bucket in a region other than the one you intended.

There are some rules while using "locationConstraint":

  1. region "us-east-1" is compatible with all regions in "locationConstraint"
  2. With any other region, region and locationConstraint has to be same.

In short:

  • With "us-east-1" only, You can use any region as locationConstraint to create bucket in desired region.(region='us-east-1' locationConstraint=)
  • With all other region region and locationConstraint should be the same(region='us-west-2', locationConstraint='us-west-2') any other region will throw "code:IllegalLocationConstraintException"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!