

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

# Amazon S3 Access Grants mit JupyterLab Studio-Notebooks Connect
<a name="s3-access-grants-setup"></a>

Verwenden Sie die folgenden Informationen, um Amazon S3-Zugriffsberechtigungen in JupyterLab Studio-Notizbüchern zu gewähren.

Nachdem Amazon S3 Access Grants eingerichtet ist, [fügen Sie die folgenden Berechtigungen](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html) Ihrer Domain- oder [Benutzerausführungsrolle](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-roles.html#sagemaker-roles-get-execution-role) hinzu.
+ `us-east-1` ist die AWS-Region
+ `111122223333` ist die AWS-Konto -ID
+ `S3-ACCESS-GRANT-ROLE` ist die Rolle von Amazon S3 Access Grant

------
#### [ 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"
        }
    ]
}
```

------

Stellen Sie sicher, dass die Vertrauensrichtlinie Ihrer Rolle von Amazon S3 Access Grants die Aktionen `sts:SetContext` und `sts:AssumeRole` zulässt. Folgendes ist eine Beispielrichtlinie, wenn Sie die [Vertrauensrichtlinie für Ihre Rolle aktualisieren](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_update-role-trust-policy.html).

------
#### [ 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"
                }
            }
        }
    ]
}
```

------

## Verwenden von Amazon S3 Access Grants für den Aufruf von Amazon S3
<a name="s3-access-grants-python-example"></a>

Im Folgenden finden Sie ein Beispiel für ein Python-Skript, das zeigt, wie Amazon S3 Access Grants verwendet werden kann, um Amazon S3 aufzurufen. Dies setzt voraus, dass Sie die Verbreitung vertrauenswürdiger Identitäten mit SageMaker KI bereits erfolgreich eingerichtet haben.

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

Wenn Sie einen Pfad zu einem Amazon-S3-Bucket verwenden, für den Amazon S3 Access Grant nicht aktiviert ist, schlägt der Aufruf fehl.

Weitere Informationen zu anderen Programmiersprachen finden Sie unter [Verwalten des Zugriffs mit Amazon S3 Access Grants](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants.html).