Study & Practice

北海道札幌市のプログラマによる技術とか雑記のブログ

AWS CLIでS3バケットを作ろうとしたら「The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.」を言われた時の対処法

CodeDeployのためにS3バケットを作るために

aws s3api create-bucket --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.

というエラーが返ってきた。

リージョンが指定されていないという内容のようなので以下のようにリージョンを指定してコマンドを実行したが同じエラーが出てきた。

aws s3api create-bucket --bucket バケット名 --region ap-northeast-1

公式ドキュメントのExamplesにも

aws s3api create-bucket --bucket my-bucket --region us-east-1

というコマンドが記載されているが動かなかった

と思ったらもう少し下にus-east-1以外のリージョンを使いたいならLocationConstraintっていうのを使えと書いてあった

LocationConstraintは--create-bucket-configurationというオプションで指定する項目でリージョンにap-northeast-1を指定する場合は以下のような使い方になる

aws s3api create-bucket --bucket バケット名 --region ap-northeast-1 --create-bucket-configuration LocationConstraint=ap-northeast-1

ちなみにこのコマンドだとリージョン2回指定してるじゃんと思って以下のようなコマンドを実行してみたところ正常にバケットが作られた。--regionオプションは使わなくても大丈夫みたい

aws s3api create-bucket --bucket バケット名 --create-bucket-configuration LocationConstraint=ap-northeast-1

ただ公式ドキュメントには--regionもLocationConstraintも両方指定するコマンドが載ってるしどっかで不具合が起きるかもしれないのでちゃんと両方指定しておくのが安全かなと思います。