

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 設定 Amazon SageMaker 模型卡的跨帳戶支援
<a name="model-cards-xaccount"></a>

在 Amazon SageMaker 模型卡中使用跨帳戶支援，在 AWS 帳戶之間共用模型卡。建立模型卡的帳戶是*模型卡帳戶*。模型卡帳戶中的使用者與*共用帳戶*共享它們。共用帳戶中的使用者可以更新模型卡或建立其 PDF。

模型卡帳戶中的使用者透過 AWS Resource Access Manager (AWS RAM) 共用其模型卡。 AWS RAM 可協助您跨 AWS 帳戶共用資源。如需 的簡介 AWS RAM，請參閱[什麼是 AWS Resource Access Manager？](https://docs.aws.amazon.com/ram/latest/userguide/what-is.html)

以下是共享模型卡的過程：

1. 模型卡帳戶中的使用者使用 AWS Resource Access Manager設定跨帳戶模型卡共享。

1. 如果模型卡使用 AWS KMS 金鑰加密，則設定模型共用的使用者也必須為共用帳戶中的使用者提供 AWS KMS 許可。

1. 共用帳戶中的使用者接受資源共用的邀請。

1. 共用帳戶中的使用者為其他使用者提供了存取模型卡的許可。

如果您是模型卡帳戶的使用者，請參閱以下章節：
+ [設定跨帳戶模型卡分享](#model-cards-xaccount-set-up)
+ [設定共用帳戶的 AWS KMS 許可](#model-cards-xaccount-kms)
+ [取得資源共用邀請的回應](#model-cards-xaccount-set-up-responses)

如果您是共用帳戶的使用者，請參閱[在共用帳戶中設定 IAM 使用者許可](#model-cards-xaccount-shared-account-permissions)關於為自己和帳戶中其他使用者設定許可的相關資訊。

## 設定跨帳戶模型卡分享
<a name="model-cards-xaccount-set-up"></a>

使用 AWS Resource Access Manager (AWS RAM) 授予您 AWS 帳戶中的使用者檢視或更新在不同 AWS 帳戶中建立之模型卡的存取權。

若要設定模型卡共用，您必須建立資源共用。資源共享指定：
+ 正在共享的資源
+ 誰或什麼有權存取資源
+ 資源的受管許可

如需有關資源共用的更多相關資訊，請參閱[AWS RAM詞彙和概念](https://docs.aws.amazon.com/ram/latest/userguide/getting-started-terms-and-concepts.html)。我們建議您先花時間 AWS RAM 從概念上了解，再進行建立資源共享的程序。

**重要**  
您必須擁有許可才能建立資源共用。如需許可的詳細資訊，請參閱 [AWS RAM 如何使用 IAM](https://docs.aws.amazon.com/ram/latest/userguide/security-iam-policies.html)。

如需建立資源共用的程序及其相關資訊，請參閱[建立資源共用](https://docs.aws.amazon.com/ram/latest/userguide/getting-started-sharing.html#getting-started-sharing-create)。

當您執行建立資源共用的程序時，您指定`sagemaker:ModelCard`為資源類型。您還必須指定 AWS RAM 資源型政策的 Amazon Resource Number (ARN)。您可以指定預設政策或具有建立模型卡 PDF 之其他許可的政策。

使用預設`AWSRAMPermissionSageMakerModelCards`資源型政策，共用帳戶中的使用者具有執行以下作業的許可：
+  [DescribeModelCard](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeModelCard.html)
+ [ListModelCardVersions](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ListModelCardVersions.html)
+ [UpdateModelCard](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateModelCard.html)

使用`AWSRAMPermissionSageMakerModelCardsAllowExport`資源型政策，共用帳戶中的使用者擁有執行上述所有動作的許可。他們還具有建立模型卡匯出任務的許可，並透過以下操作對其進行描述：
+ [CreateModelCardExportJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModelCardExportJob.html)
+ [DescribeModelCardExportJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeModelCardExportJob.html)

共用帳戶中的使用者可以建立匯出任務以生成模型卡的 PDF。他們也可以描述為尋找 PDF 的 Amazon S3 URI 而建立的匯出任務。

模型卡和匯出任務為資源。模型卡帳戶擁有使用者在共用帳戶中建立的匯出任務。例如，帳戶 A 中的使用者與共用帳戶 B 共用模型卡 X。帳戶 B 中的使用者會為模型卡 X 建立匯出任務 Y，該模型卡 X 將輸出存放在使用者帳戶 B 指定的 Amazon S3 位置。即使帳戶 B 建立了匯出任務 Y，其仍屬於帳戶 A。

每個 AWS 帳戶都有資源配額。如需與模型卡相關配額的相關資訊，請參閱 [Amazon SageMaker AI 端點和配額](https://docs.aws.amazon.com/general/latest/gr/sagemaker.html#limits_sagemaker)。

### 設定共用帳戶的 AWS KMS 許可
<a name="model-cards-xaccount-kms"></a>

如果您要共用的模型卡已使用 AWS Key Management Service 金鑰加密，您也需要與共用帳戶共用金鑰的存取權。否則，共用帳戶中的使用者將無法檢視、更新或匯出模型卡。如需 的概觀 AWS KMS，請參閱 [AWS Key Management Service](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)。

若要提供 AWS KMS 許可給共用帳戶中的使用者，請使用下列陳述式更新您的金鑰政策：

```
{
    "Effect": "Allow",
    "Principal": {
        "AWS": [
            "arn:aws:iam::shared-account-id::role/example-IAM-role"
        ]
    },
    "Action": [
        "kms:GenerateDataKey",
        "kms:Decrypt",
    ]
    "Resource": "arn:aws:kms:AWS-Region-of-model-card-account:model-card-account-id:key/AWS KMS-key-id"
    "Condition": {
        "Bool": {"kms:GrantIsForAWSResource": true },
        "StringEquals": {
            "kms:ViaService": [
                "sagemaker.AWS-Region.amazonaws.com", 
                "s3.AWS-Region.amazonaws.com"
            ],
        },
        "StringLike": {
          "kms:EncryptionContext:aws:sagemaker:model-card-arn": "arn:aws:sagemaker:AWS-Region:model-card-account-id:model-card/model-card-name"
        }
    }    
}
```

上述陳述式為共用帳戶中的使用者提供`kms:Decrypt`和`kms:GenerateDataKey`許可。使用`kms:Decrypt`，使用者可以解密模型卡。使用`kms:GenerateDataKey`，使用者可以加密他們更新的模型卡或建立的 PDF。

### 取得資源共用邀請的回應
<a name="model-cards-xaccount-set-up-responses"></a>

建立資源共用之後，您在資源共用中指定的共用帳戶會收到加入該共用帳號的邀請。他們必須接受邀請才能存取資源。

如需有關接受資源共用邀請的資訊，請參閱*AWS 《Resource Access Manager 使用者指南*》中的[使用共用 AWS 資源](https://docs.aws.amazon.com/ram/latest/userguide/getting-started-shared.html)。

### 在共用帳戶中設定 IAM 使用者許可
<a name="model-cards-xaccount-shared-account-permissions"></a>

以下資訊假設您已接受來自模型卡帳戶的資源共用邀請。如需接受資源共用邀請的詳細資訊，請參閱[使用共用 AWS 資源。 ](https://docs.aws.amazon.com/ram/latest/userguide/getting-started-shared.html)

您和帳戶中的其他使用者使用 IAM 角色來存取在模型卡帳戶中共用的模型卡。使用以下範本變更 IAM 角色的政策。您可以針對自己的使用案例修改範本。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:DescribeModelCard",
                "sagemaker:UpdateModelCard",
                "sagemaker:CreateModelCardExportJob",
                "sagemaker:ListModelCardVersions",
                "sagemaker:DescribeModelCardExportJob"
            ],
            "Resource": [
                "arn:aws:sagemaker:us-east-1:111122223333:model-card/example-model-card-name-0",
                "arn:aws:sagemaker:us-east-1:111122223333:model-card/example-model-card-name-1/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket-storing-the-pdf-of-the-model-card/model-card-name/*"
        }
    ]
}
```

------

若要存取使用 加密的模型卡 AWS KMS，您必須為帳戶中的使用者提供下列 AWS KMS 許可。

```
{
     "Effect": "Allow",
     "Action": [
         "kms:GenerateDataKey",
         "kms:Decrypt",
     ],
     "Resource": "arn:aws:kms:AWS-Region:AWS-account-id-where-the-model-card-is-created:key/AWS Key Management Service-key-id"
}
```