LoginSignup
2
1

More than 3 years have passed since last update.

めったにやらないAWS CLIでS3バケットを作成&設定する方法を思い出すためのメモ

Last updated at Posted at 2021-03-10

TL;DR

  • めったに無いけどS3 bucketを手動で作成する場合にaws cliのs3apiを思い出す時間短縮のためのメモです
    • TerraformやCDKを使いたいけど使いにくい場合など。でも手で作るのは嫌だ
  • ここを見ればリファレンスをさまよわなくてもs3apiにたどり着くよね
  • AWS CloudShellは便利だね

よくあるS3 bucket設定値


BUCKET_NAME=hogehogefugafuga

# Create Bucket
aws s3api create-bucket --bucket ${BUCKET_NAME} --region ap-northeast-1 --create-bucket-configuration LocationConstraint=ap-northeast-1

#
# Versioning
#
## Enable Versioning
aws s3api put-bucket-versioning --bucket ${BUCKET_NAME} --versioning-configuration Status=Enabled
## Confirmaton
aws s3api get-bucket-versioning --bucket ${BUCKET_NAME}
{
    "Status": "Enabled"
}

#
# Public Block Access
#
## Set
aws s3api put-public-access-block --bucket ${BUCKET_NAME} --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
## Confirmation
aws s3api get-public-access-block --bucket ${BUCKET_NAME}
{
    "PublicAccessBlockConfiguration": {
        "BlockPublicAcls": true,
        "IgnorePublicAcls": true,
        "BlockPublicPolicy": true,
        "RestrictPublicBuckets": true
    }
}

^で作成されるbucketの設定値はこんな感じ

- プロパティ
    - バケットの概要
        - region: ap-northeast-1
    - バケットのバージョニング
        - バケットのバージョニング: 有効
        - Multi-Factor Authentication (MFA) の削除: 無効
    - タグ
        なし
    - デフォルトの暗号化
        - デフォルトの暗号化: 無効
    - Intelligent-Tiering Archive 設定
        なし
    - サーバーアクセスのログ記録
        - サーバーアクセスのログ記録: 無効
    - AWS CloudTrail データイベント
        設定してね
    - イベント通知
        なし
    - Transfer Acceleration
        - Transfer Acceleration: 無効
    - オブジェクトロック
        - オブジェクトロック: 無効
    - リクエスタ支払い
        - リクエスタ支払い: 無効
    - 静的ウェブサイトホスティング
        - 静的ウェブサイトホスティング: 無効
- アクセス許可
    - アクセス許可の概要
        - アクセス: 非公開のバケットとオブジェクト *デフォルト(ブロックパブリックアクセスオン時)
    - ブロックパブリックアクセス (バケット設定)
        - ブロックパブリックアクセス (バケット設定): 全てオン
    - バケットポリシー
        なし
    - オブジェクト所有者
        - オブジェクト所有者: オブジェクトライター *デフォルト
    - アクセスコントロールリスト (ACL)
        - バケット所有者 (AWS アカウント)のみ *デフォルト
            - オブジェクト: リスト、書き込み
            - バケットACL: 読み取り、書き込み
    - Cross-Origin Resource Sharing (CORS)
        なし
- メトリクス
    デフォルト
- 管理
    デフォルト
- アクセスポイント
    デフォルト(なし)

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