Connetti Amazon S3 Access Grants ai notebook Studio JupyterLab - Amazon SageMaker AI

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Connetti Amazon S3 Access Grants ai notebook Studio JupyterLab

Utilizza le seguenti informazioni per concedere Amazon S3 Access Grants nei notebook Studio. JupyterLab

Dopo aver configurato Amazon S3 Access Grants, aggiungi le autorizzazioni seguenti al ruolo di esecuzione del dominio o dell’utente.

  • us-east-1 è la tua Regione AWS.

  • 111122223333 è il tuo ID Account AWS .

  • S3-ACCESS-GRANT-ROLE è il tuo ruolo Amazon S3 Access Grants.

JSON
{ "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" } ] }

Verifica che la policy di attendibilità del tuo ruolo Amazon S3 Access Grants consenta le azioni sts:SetContext e sts:AssumeRole. Di seguito è riportato un esempio di policy da utilizzare quando aggiorni la policy di attendibilità del ruolo.

JSON
{ "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" } } } ] }

Utilizzo di Amazon S3 Access Grants per chiamare Amazon S3

Di seguito è riportato un esempio di script Python che mostra come utilizzare Amazon S3 Access Grants per chiamare Amazon S3. Ciò presuppone che tu abbia già configurato correttamente la propagazione delle identità affidabili con l'intelligenza artificiale. SageMaker

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/")

Se utilizzi un percorso di un bucket Amazon S3 in cui non è abilitato Amazon S3 Access Grants, la chiamata non riuscirà.

Per ulteriori informazioni su altri linguaggi di programmazione, consulta Managing access with Amazon S3 Access Grants.