Studio JupyterLab ノートブックで Amazon S3 Access Grants を接続する - Amazon SageMaker AI

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Studio JupyterLab ノートブックで Amazon S3 Access Grants を接続する

Studio JupyterLab ノートブックで Amazon S3 Access Grants を付与するには、次の情報を使用します。

Amazon S3 Access Grants を設定したら、ドメインまたはユーザー実行ロール次のアクセス許可を追加します

  • us-east-1 は AWS リージョン

  • 111122223333 は AWS アカウント ID です

  • S3-ACCESS-GRANT-ROLE は Amazon S3 Access Grant ロールです

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowDataAccessAPI", "Effect": "Allow", "Action": [ "s3:GetDataAccess" ], "Resource": [ "arn:aws:s3:us-east-1:111122223333:access-grants/default" ] }, { "Sid": "RequiredForTIP", "Effect": "Allow", "Action": "sts:SetContext", "Resource": "arn:aws:iam::111122223333:role/S3-ACCESS-GRANT-ROLE" } ] }

Amazon S3 Access Grants ロールの信頼ポリシーで sts:SetContextおよび sts:AssumeRoleアクションが許可されていることを確認します。ロールの信頼ポリシーを更新する場合の ポリシーの例を次に示します。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ "access-grants.s3.amazonaws.com" ] }, "Action": [ "sts:AssumeRole", "sts:SetContext" ], "Condition": { "StringEquals": { "aws:SourceAccount": "111122223333", "aws:SourceArn": "arn:aws:s3:us-east-1:111122223333:access-grants/default" } } } ] }

Amazon S3 Access Grants を使用して Amazon S3 を呼び出す

以下は、Amazon S3 Access Grants を使用して Amazon S3 を呼び出す方法を示す Python スクリプトの例です。これは、SageMaker AI で信頼できる ID 伝達を正常にセットアップしていることを前提としています。

import boto3 from botocore.config import Config def get_access_grant_credentials(account_id: str, target: str, permission: str = 'READ'): s3control = boto3.client('s3control') response = s3control.get_data_access( AccountId=account_id, Target=target, Permission=permission ) return response['Credentials'] def create_s3_client_from_credentials(credentials) -> boto3.client: return boto3.client( 's3', aws_access_key_id=credentials['AccessKeyId'], aws_secret_access_key=credentials['SecretAccessKey'], aws_session_token=credentials['SessionToken'] ) # Create client credentials = get_access_grant_credentials('111122223333', "s3://tip-enabled-bucket/tip-enabled-path/") s3 = create_s3_client_from_credentials(credentials) s3.list_objects(Bucket="tip-enabled-bucket", Prefix="tip-enabled-path/")

Amazon S3 アクセス許可が有効になっていない Amazon S3 バケットへのパスを使用すると、呼び出しは失敗します。

その他のプログラミング言語の詳細については、Amazon S3 Access Grants によるアクセスの管理」を参照してください。