LoginSignup
11
1

More than 1 year has passed since last update.

【AWS CLI】ap-northeast-1でcreate-bucketした際にIllegalLocationConstraintExceptionがスローされた場合の対処法

Last updated at Posted at 2021-06-01

はじめに

以下のエラーが発生した際の対処法です。

$ aws s3api create-bucket --bucket test-bucket

# An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.

結論

--create-bucket-configurationLocationConstraint=$regionを指定する必要があります。
(今回であれば--create-bucket-configuration LocationConstraint=ap-northeast-1)

$ aws s3api create-bucket --bucket test-bucket --create-bucket-configuration LocationConstraint=ap-northeast-1

# {
#     "Location": "http://test-bucket.s3.amazonaws.com/"
# }

詳細

公式リファレンスに全て記載があります。

LocationConstraint:

Specifies the Region where the bucket will be created. If you don't specify a Region, the bucket is created in the US East (N. Virginia) Region (us-east-1).

LocationConstraintには、バケットを作成するリージョンを指定します。
LocationConstraintを指定しない場合、バケットは米国東部 (バージニア北部) リージョン (us-east-1) に作成されます。

If you send your create bucket request to the s3.amazonaws.com endpoint, the request goes to the us-east-1 Region.
~~
Regions outside of us-east-1 require the appropriate LocationConstraint to be specified in order to create the bucket in the desired region:

上述したようにcreate-bucketリクエストは、デフォルトでは us-east-1に送信されます。

そのため、us-east-1 以外にバケットを作成する場合は、そのリージョンを LocationConstraint に指定する必要があります。

逆に言えば、us-east-1からリクエストを送信する場合は、--create-bucket-configurationを指定する必要がありません。
またその場合は、us-east-1にバケットが作成されます。

$ aws s3api create-bucket --bucket test-bucket2 --region us-east-1

# {
#     "Location": "/test-bucket2"
# }


参考

11
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
1