LoginSignup
1
0

More than 3 years have passed since last update.

AWS SDKやCLIでS3に対するアカウントレベルの操作を行う場合はS3 Controlを利用する

Last updated at Posted at 2020-02-05

はじめに

AWS SDKからアカウントレベルでブロックパブリックアクセスの設定を行いたかったのですが
SDKドキュメントのs3の項目にはバケット単位で設定を行う項目はあるものの、
アカウントレベルで設定を行う項目が見当たりません。
アカウントレベルで設定を行うには AWS S3 Control に対してAPIリクエストを行う必要がありました。

AWS S3 Control

AWS S3 Controlは、アカウントレベルのブロックパブリックアクセス設定や
バッチオペレーション、アクセスポイントの管理など、
Amazon S3 コントロールプレーンに対するオペレーションのアクセスを提供します。

提供されているアクションは以下のドキュメントを参照

Amazon S3 API Reference - AWS S3 Control
https://docs.aws.amazon.com/AmazonS3/latest/API/API_Operations_AWS_S3_Control.html

アカウントレベルのブロックパブリックアクセスを設定する場合の例です。

Boto3

以下のように実行します。

import boto3

client = boto3.client('s3control')

response = client.put_public_access_block(
    PublicAccessBlockConfiguration={
        'BlockPublicAcls': True,
        'IgnorePublicAcls': True,
        'BlockPublicPolicy': True,
        'RestrictPublicBuckets': True
    },
    AccountId='123456789012'
)

ドキュメントは以下です。

Boto3 Docs / Available Services / S3Control
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3control.html

AWS CLI

以下のように実行します。

$ aws s3control put-public-access-block --account-id 123456789012 \
--public-access-block-configuration "BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true"

コマンドリファレンスは以下です。

AWS CLI Command Reference - S3 Control
https://docs.aws.amazon.com/cli/latest/reference/s3control/index.html

その他の言語の例やリンクについては割愛させていただきます。
以上です。

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