

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

# 設定預備建構模組範例
<a name="model-registry-staging-construct-set-up"></a>

若要為您的 Amazon SageMaker 模型註冊表設定階段建構模組，管理員需要將相關許可授予預期的角色。以下提供如何為各種角色設定階段建構模組的範例。

**注意**  
Amazon SageMaker AI 網域內的使用者將能夠檢視網域內定義的所有階段，但只能使用他們具有許可的階段。

階段由 `ModelLifeCycle` 參數定義，並具有下列結構。管理員會設定哪些角色可以存取 `stage` 和 `stageStatus` 的許可。擔任角色的使用者可以使用相關的 `stage` 和 `stageStatus`，並包括自己的 `stageDescription`。

```
ModelLifeCycle {
    stage: String # Required (e.g., Development/QA/Production)
    stageStatus: String # Required (e.g., PendingApproval/Approved/Rejected)  
    stageDescription: String # Optional
}
```

下表包含模型註冊庫預先定義的階段建構模組範本。您可以根據您的使用案例定義自己的階段建構模組。必須先設定相關許可，使用者才能使用這些許可。


| 階段 | 階段狀態 | 
| --- | --- | 
|  提案  |  PendingApproval  | 
|  開發  |  InProgress  | 
|  QA  |  OnHold  | 
|  PreProduction  |  Approved  | 
|  生產  |  已拒絕  | 
|  已封存  |  已淘汰  | 

下列 API 可以調用 `ModelLifeCycle` 參數：
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModelPackage.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModelPackage.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateModelPackage.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateModelPackage.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeModelPackage.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeModelPackage.html)

------
#### [ Policy for a data scientist role ]

以下是使用模型生命週期條件金鑰的範例 IAM 政策。您可以根據自己的要求修改它們。在此範例中，角色的許可僅限於設定或定義模型生命週期階段，以：
+ 建立或更新階段為 `"Development"` 和狀態為 `"Approved"` 的模型。
+ 使用階段品質保證、`"QA"` 和狀態 `"PendingApproval"` 更新模型套件。

```
{
    "Action" : [
        "sagemaker:UpdateModelPackage",
        "sagemaker:CreateModelPackage"
    ],
    "Resource": [
        "*"
    ],
    "Condition": {
        "StringEquals": {
            "sagemaker:ModelLifeCycle:stage" : "Development"
            "sagemaker:ModelLifeCycle:stageStatus" : "Approved"       
        }
    }
},
{
    "Action" : [
        "sagemaker:UpdateModelPackage"
    ],
    "Resource": [
        "*"
    ],
    "Condition": {
        "StringEquals": {
            "sagemaker:ModelLifeCycle:stage" : "Staging"
            "sagemaker:ModelLifeCycle:stageStatus" : "PendingApproval"       
        }
    }
}
```

------
#### [ Policy for a quality assurance specialist ]

以下是使用模型生命週期條件金鑰的範例 IAM 政策。您可以根據自己的要求修改它們。在此範例中，角色的許可僅限於設定或定義模型生命週期階段，以：
+ 使用下列內容更新模型套件：
  + 階段 `"QA"` 和狀態 `"Approved"` 或 `"Rejected"`。
  + 階段 `"Production"` 和狀態 `"PendingApproval"`。

```
{
    "Action": [
        "sagemaker:UpdateModelPackage"
    ],
    "Resource": [
        "*"
    ],
    "Condition": {
        "StringEquals": {
            "sagemaker:ModelLifeCycle:stage": "Staging",
            "sagemaker:ModelLifeCycle:stageStatus": "Approved"
        }
    }
}, {
    "Action": [
        "sagemaker:UpdateModelPackage"
    ],
    "Resource": [
        "*"
    ],
    "Condition": {
        "StringEquals": {
            "sagemaker:ModelLifeCycle:stage": "Staging",
            "sagemaker:ModelLifeCycle:stageStatus": "Rejected"
        }
    }
}, {
    "Action": [
        "sagemaker:UpdateModelPackage"
    ],
    "Resource": [
        "*"
    ],
    "Condition": {
        "StringEquals": {
            "sagemaker:ModelLifeCycle:stage": "Production",
            "sagemaker:ModelLifeCycle:stageStatus": "PendingApproval"
        }
    }
}
```

------
#### [ Policy for lead engineer role ]

以下是使用模型生命週期條件金鑰的範例 IAM 政策。您可以根據自己的要求修改它們。在此範例中，角色的許可僅限於設定或定義模型生命週期階段，以：
+ 使用下列內容更新模型套件：
  + 階段 `"Production"` 和狀態 `"Approved"` 或 `"Rejected"`。
  + 階段 `"Development"` 和狀態 `"PendingApproval"`。

```
{
    "Action" : [
        "sagemaker:UpdateModelPackage"
    ],
    "Resource": [
        "*"
    ],
    "Condition": {
        "ForAnyvalue:StringEquals" : {
            "sagemaker:ModelLifeCycle:stage" : "Production",
            "sagemaker:ModelLifeCycle:stageStatus" : "Approved"
        }
    }
},
{
    "Action" : [
        "sagemaker:UpdateModelPackage"
    ],
    "Resource": [
        "*"
    ],
    "Condition": {
        "StringEquals:" {
            "sagemaker:ModelLifeCycle:stage" : "Production"
            "sagemaker:ModelLifeCycle:stageStatus" : "Rejected"
        }
    }
},
{
    "Action" : [
        "sagemaker:UpdateModelPackage"
    ],
    "Resource": [
        "*"
    ],
    "Condition": {
        "StringEquals": {
            "sagemaker:ModelLifeCycle:stage" : "Development"
            "sagemaker:ModelLifeCycle:stageStatus" : "PendingApproval"
        }
    }
}
```

------

若要取得任何模型狀態更新的 Amazon EventBridge 通知，請參閱[取得 ModelLifeCycle 的事件通知](model-registry-staging-construct-event-bridge.md)中的範例。如需您可能會收到的範例 EventBridge 承載，請參閱 [SageMaker 模型套件狀態變更](automating-sagemaker-with-eventbridge.md#eventbridge-model-package)。