1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS S3のバケット名は全アカウントでユニークである必要があるという仕様への対処法

Last updated at Posted at 2019-07-15

はじめに

S3のバケット名は全アカウントでユニークである必要があるため、既に存在しているバケット名ではバケットを作成できない。

$ aws s3 mb s3://dev
make_bucket failed: s3://dev An error occurred (BucketAlreadyExists) when calling the CreateBucket operation: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.

対処方法

AWS Account IDのmd5ハッシュを利用する。
こうすればAWSアカウントが同一である限り、バケット名の恒久性とユニーク性が同時に確保できる。

# AWSCLIで取得したAccountIDのmd5ハッシュ文字列の先頭10文字を取得
$ backet_hash=$(echo -n $(aws sts get-caller-identity | jq -r .Account) | md5sum | cut -c 1-10)

取得したハッシュに必要に応じて日付や目的がわかる文字列を付加してバケット名にすればOK。

# ハッシュ値 + 現在日付(YYYYmmdd) + 「dev」のバケット名でS3バケット作成
$ aws s3 mb s3://${backet_hash}-$(date +%Y%m%d)-dev
make_bucket: 12345abcde-20190715-dev

バケット名にアンダースコア_や大文字は利用できないので注意。

以上

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?