

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Amazon S3 Access Grants를 Studio JupyterLab 노트북과 연결
<a name="s3-access-grants-setup"></a>

다음 정보를 사용하여 Studio JupyterLab 노트북에서 Amazon S3 Access Grants를 부여합니다.

Amazon S3 Access Grants를 설정한 후 도메인 또는 사용자 [실행 역할](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-roles.html#sagemaker-roles-get-execution-role)에 [다음 권한을 추가](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)합니다.
+ `us-east-1`은 AWS 리전입니다.
+ `111122223333`는 AWS 계정 ID입니다.
+ `S3-ACCESS-GRANT-ROLE`은 Amazon S3 액세스 권한 부여 역할입니다.

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

------

Amazon S3 Access Grants 역할의 신뢰 정책이 `sts:SetContext` 및 `sts:AssumeRole` 작업을 허용해야 합니다. 다음은 [역할 신뢰 정책을 업데이트](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"
                }
            }
        }
    ]
}
```

------

## Amazon S3 Access Grants를 사용하여 Amazon S3 직접적으로 호출
<a name="s3-access-grants-python-example"></a>

다음은 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를 통한 액세스 관리](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants.html)를 참조하세요.