LoginSignup
1
0

More than 5 years have passed since last update.

[JAWS-UG CLI] S3:#15 バケットの作成 (作業ログ用)

Last updated at Posted at 2017-02-13

前提条件

S3への権限

S3に対してフル権限があること。

AWS CLIのバージョン

以下のバージョンで動作確認済

  • AWS CLI 1.11.28
コマンド
aws --version

結果(例):

  aws-cli/1.11.34 Python/2.7.10 Darwin/15.6.0 botocore/1.4.91

バージョンが古い場合は最新版に更新しましょう。

コマンド
sudo -H pip install -U awscli

0. 準備

0.1. リージョンの決定

作成するS3バケットのリージョンを決めます。

(カレントユーザが利用するカレントリージョンも切り変わります。)

変数の設定
export AWS_DEFAULT_REGION='ap-northeast-1'

0.2. プロファイルの確認

プロファイルが想定のものになっていることを確認します。

コマンド
aws configure list

結果(例)

        Name                    Value             Type    Location
        ----                    -----             ----    --------
     profile         s3Full-prjZ-mbp13        env    AWS_DEFAULT_PROFILE
  access_key     ****************XXXX shared-credentials-file
  secret_key     ****************XXXX shared-credentials-file
      region                         ap-northeast-1  env    AWS_DEFAULT_REGION

AssumeRoleを利用している場合はprofileが ''と表示されます。 そ
れ以外のときにprofileが '' と表示される場合は、以下を実行して
ください。

変数の設定:

     export AWS_DEFAULT_PROFILE=<IAMユーザ名>

1. 事前作業

1.1. プレフィクスの指定

変数の設定
S3_BUCKET_PREFIX='log'

1.2. AWS IDの取得

変数の設定
AWS_ID=$( \
        aws sts get-caller-identity \
          --query 'Account' \
          --output text \
) && echo ${AWS_ID}

結果(例)

  XXXXXXXXXXXX

1.3. バケット名の決定

変数の設定
S3_BUCKET_NAME="${S3_BUCKET_PREFIX}-${AWS_ID}" \
        && echo ${S3_BUCKET_NAME}

同名バケットが存在しないことを確認します。

コマンド
aws s3 ls s3://${S3_BUCKET_NAME}/

結果(例):

  A client error (NoSuchBucket) occurred when calling the ListObjects operation: The specified bucket does not exist

2. バケットの作成

変数の確認
cat << ETX

        S3_BUCKET_NAME:     ${S3_BUCKET_NAME}
        AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}

ETX
コマンド
aws s3api create-bucket \
        --bucket ${S3_BUCKET_NAME} \
        --create-bucket-configuration "LocationConstraint=${AWS_DEFAULT_REGION}"

結果(例):

  {
    "Location": "http://log-XXXXXXXXXXXX.s3.amazonaws.com/"
  }

3. 事後確認

コマンド
aws s3api get-bucket-location \
        --bucket ${S3_BUCKET_NAME}

結果(例):

  {
    "LocationConstraint": "ap-northeast-1"
  }

完了

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