Connessione di Amazon S3 Access Grants ai notebook JupyterLab di Studio
Utilizza le informazioni seguenti per abilitare Amazon S3 Access Grants nei notebook JupyterLab di Studio.
Dopo aver configurato Amazon S3 Access Grants, aggiungi le autorizzazioni seguenti al ruolo di esecuzione del dominio o dell’utente.
-
è la tua Regione AWS.us-east-1 -
è il tuo ID Account AWS.111122223333 -
è il tuo ruolo Amazon S3 Access Grants.S3-ACCESS-GRANT-ROLE
{ "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.
{ "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. Si presuppone che tu abbia già impostato correttamente la propagazione attendibile delle identità con SageMaker AI.
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.