LoginSignup
15
9

More than 5 years have passed since last update.

S3 バケットが取れるまで頑張るスクリプト

Posted at

ある AWS アカウントで取った S3 バケットを、別のアカウントの持ち物にしたくなったとき、同名のバケットを同時に作ることはできないので、一旦元のアカウントのバケットを削除してから、別のアカウントで作ることになります。

その際、別のアカウントですぐ作ろうとしても、こんなメッセージが出て作れません。

A conflicting conditional operation is currently in progress against this resource. Please try again.

じゃぁどうするか?取れるまで自動で叩くしかないでしょう。

AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY が export されているなど、適切な権限がある状態で、このシェルスクリプトを実行して下さい。your-bucket-nameyour-region-name は適当に書き換えて下さい。

while :; do
  date
  aws s3api create-bucket --bucket your-bucket-name --create-bucket-configuration LocationConstraint=your-region-name && break
  sleep 60
done

ファイルにした版はこちら: i-want-this-bucket.sh

個人的にハマったのが、リージョン指定。AWS_DEFAULT_REGION を指定してもうまくいかず、--region ap-northeast-1 としてもうまくいかず。結論、上記のように --create-bucket-configuration を指定する必要がありました。

参考: [1.2.10][s3api] IllegalLocationConstraintException when using dots in bucket name · Issue #589 · aws/aws-cli

15
9
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
15
9