

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

# 從私有工作者入口網站使用 Amazon VPC 模式
<a name="samurai-vpc-worker-portal"></a>

若要將工作者入口網站存取權限限制為在 Amazon VPC 內工作的標籤者，您可以在建立 Ground Truth 私有人力資源時新增 VPC 組態。您也可以將 VPC 組態新增至現有的私有人力資源。Ground Truth 會自動在您的 VPC 中建立 VPC 介面端點，並在您的 VPC 端點和 Ground Truth 服務之間設定 AWS PrivateLink 。可從您的 VPC 存取與該人力資源建立關聯的工作者入口網站 URL。亦可從公有網際網路存取工作者入口網站 URL，直到您對公有網際網路設定限制。從您的人力資源刪除人力或移除 VPC 組態時，Ground Truth 會自動刪除與該人力資源建立關聯的 VPC 端點。

**注意**  
一個人力資源僅可由一個 VPC 支援。

[點雲](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-point-cloud.html)和[影片](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-video.html)任務不支援透過 VPC 載入。

本指南示範如何完成在您的人力資源中新增和刪除 Amazon VPC 組態的必要步驟，以及滿足先決條件。

## 先決條件
<a name="samurai-vpc-getting-started-prerequisites"></a>

若要在 Amazon VPC 執行 Ground Truth 標籤工作，請檢閱下列先決條件。
+ 您已設定您可使用的 Amazon VPC。如果您尚未設定 VPC，請按照以下指示[建立 VPC](https://docs.aws.amazon.com/vpc/latest/privatelink/create-interface-endpoint.html#interface-endpoint-shared-subnets)。
+ 視[工作者任務範本](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-instructions-overview.html)的寫入方式而定，在標籤任務期間，可以直接從 Amazon S3 存取存放在 Amazon S3 儲存貯體中的資料。在此情況下，必須將 VPC 網路設定為允許從人工標籤者使用的裝置到包含標籤資料的 S3 儲存貯體流量。
+ 依照[檢視和更新 VPC 的 DNS 屬性](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-dns.html#vpc-dns-updating)以啟用 VPC 的 DNS 主機名稱和 DNS 解析。

**注意**  
為您的人力資源設定 VPC 的方法有兩種。您可以透過 [主控台](https://console.aws.amazon.com/sagemaker)或 AWS SageMaker AI [CLI](https://aws.amazon.com/cli/) 執行此操作。

# 使用 SageMaker AI 主控台管理 VPC 組態
<a name="samurai-vpc-workforce-console"></a>

您可以使用 [SageMaker AI 主控台](https://console.aws.amazon.com/sagemaker)來新增或移除 VPC 組態。您也可以刪除現有的人力資源。

## 將 VPC 組態新增至您的人力資源
<a name="samurai-add-vpc-workforce"></a>

### 建立私有人力資源
<a name="samurai-vpc-create-workforce"></a>
+ [使用 Amazon Cognito 建立私有人力資源](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-workforce-private-use-cognito.html)
+ [使用 OpenID Connect (OIDC) 身分提供者 (IdP) 建立私有人力資源](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-workforce-private-use-oidc.html)。

建立私有人力資源之後，請對私有人力資源新增 VPC 組態。

1. 在主控台導覽至 [Amazon SageMaker Runtime](https://console.aws.amazon.com/sagemaker)。

1. 選取左側面板的**標籤人力資源**。

1. 選取**私有**以存取您的私有人力資源。**人力資源狀態**為**作用中**後，選取 **VPC** 旁邊的**新增**。

1. 系統提示您設定 VPC 時，請提供下列資訊：

   1. 您的 **VPC**

   1. **子網路**

      1. 確保您的 VPC 具有現有的子網路

   1. **安全群組**

      1. 
**注意**  
您無法選取超過 5 個安全群組。

   1. 填寫此資訊後，選擇**確認**。

1. 選擇**確認**後，系統會將您重新導向回**標籤人力資源**下的**私有**頁面。您在頂端應該會看到綠色橫幅，其中顯示**您已成功初始化 VPC 組態的私有人力資源更新**。人力資源狀態為**正在更新**。**刪除人力資源**按鈕的旁邊是**重新整理**按鈕，可用來擷取最新的**人力資源狀態**。人力資源狀態變更為**作用中**後，VPC 端點 ID 也會更新。

## 從您的人力資源移除 VPC 組態
<a name="samurai-remove-vpc-workforce"></a>

請使用下列資訊，使用主控台從您的人力資源移除 VPC 組態。

1. 在主控台導覽至 [Amazon SageMaker Runtime](https://console.aws.amazon.com/sagemaker)。

1. 選取左側面板的**標籤人力資源**。

1. 尋找並選取您的人力資源。

1. 在**私有人力資源摘要**下，找到 **VPC** 並選擇旁邊的**移除**。

1. 選取 **Remove** (移除)。

## 透過主控台刪除人力資源
<a name="samurai-delete-vpc-workforce"></a>

如果刪除人力資源，則不應該有任何與其關聯的團隊。只有當人力資源狀態為**作用中**或**失敗**時，才能刪除人力資源。

使用下列資訊可使用主控台刪除人力資源。

1. 在主控台導覽至 [Amazon SageMaker Runtime](https://console.aws.amazon.com/sagemaker)。

1. 選取左側面板的**標籤人力資源**。

1. 尋找並選取您的人力資源。

1. 選擇**刪除人力資源**。

1. 選擇 **刪除** 。

# 使用 SageMaker AI AWS API 管理 VPC 組態
<a name="samurai-vpc-workforce-cli"></a>

使用下列各節，進一步了解如何管理 VPCs組態，同時維護工作團隊的適當存取層級。

## 使用 VPC 組態建立人力資源
<a name="samurai-create-vpc-cli"></a>

如果帳戶已有人力資源，則必須先將其刪除。您也可以使用 VPC 組態更新人力資源。

```
aws sagemaker create-workforce --cognito-config '{"ClientId": "app-client-id","UserPool": "Pool_ID",}' --workforce-vpc-config \       
" {\"VpcId\": \"vpc-id\", \"SecurityGroupIds\": [\"sg-0123456789abcdef0\"], \"Subnets\": [\"subnet-0123456789abcdef0\"]}" --workforce-name workforce-name
{
    "WorkforceArn": "arn:aws:sagemaker:us-west-2:xxxxxxxxx:workforce/workforce-name"
}
```

描述人力資源並確保狀態為 `Initializing`。

```
aws sagemaker describe-workforce --workforce-name workforce-name
{
    "Workforce": {
        "WorkforceName": "workforce-name",
        "WorkforceArn": "arn:aws:sagemaker:us-west-2:xxxxxxxxx:workforce/workforce-name",
        "LastUpdatedDate": 1622151252.451,
        "SourceIpConfig": {
            "Cidrs": []
        },
        "SubDomain": "subdomain.us-west-2.sagamaker.aws.com",
        "CognitoConfig": {
            "UserPool": "Pool_ID",
            "ClientId": "app-client-id"
        },
        "CreateDate": 1622151252.451,
        "WorkforceVpcConfig": {
            "VpcId": "vpc-id",
            "SecurityGroupIds": [
                "sg-0123456789abcdef0"
            ],
            "Subnets": [
                "subnet-0123456789abcdef0"
            ]
        },
        "Status": "Initializing"
    }
}
```

導覽至 Amazon VPC 主控台。從左側面板選取**端點**。您的帳戶應該已建立兩個 VPC 端點。

## 為您的人力資源新增 VPC 組態
<a name="samurai-add-vpc-cli"></a>

使用下列命令，透過 VPC 組態更新非 VPC 私有人力資源。

```
aws sagemaker update-workforce --workforce-name workforce-name\
--workforce-vpc-config "{\"VpcId\": \"vpc-id\", \"SecurityGroupIds\": [\"sg-0123456789abcdef0\"], \"Subnets\": [\"subnet-0123456789abcdef0\"]}"
```

描述人力資源並確保狀態為 `Updating`。

```
aws sagemaker describe-workforce --workforce-name workforce-name
{
    "Workforce": {
        "WorkforceName": "workforce-name",
        "WorkforceArn": "arn:aws:sagemaker:us-west-2:xxxxxxxxx:workforce/workforce-name",
        "LastUpdatedDate": 1622151252.451,
        "SourceIpConfig": {
            "Cidrs": []
        },
        "SubDomain": "subdomain.us-west-2.sagamaker.aws.com",
        "CognitoConfig": {
            "UserPool": "Pool_ID",
            "ClientId": "app-client-id"
        },
        "CreateDate": 1622151252.451,
        "WorkforceVpcConfig": {
            "VpcId": "vpc-id",
            "SecurityGroupIds": [
                "sg-0123456789abcdef0"
            ],
            "Subnets": [
                "subnet-0123456789abcdef0"
            ]
        },
        "Status": "Updating"
    }
}
```

導覽至 Amazon VPC 主控台。從左側面板選取**端點**。您的帳戶應該已建立兩個 VPC 端點。

## 從您的人力資源移除 VPC 組態
<a name="samurai-remove-vpc-cli"></a>

使用空的 VPC 組態更新 VPC 私有人力資源，以移除 VPC 資源。

```
aws sagemaker update-workforce --workforce-name workforce-name\ 
--workforce-vpc-config "{}"
```

描述人力資源並確保狀態為 `Updating`。

```
aws sagemaker describe-workforce --workforce-name workforce-name
{
    "Workforce": {
        "WorkforceName": "workforce-name",
        "WorkforceArn": "arn:aws:sagemaker:us-west-2:xxxxxxxxx:workforce/workforce-name",
        "LastUpdatedDate": 1622151252.451,
        "SourceIpConfig": {
            "Cidrs": []
        },
        "SubDomain": "subdomain.us-west-2.sagamaker.aws.com",
        "CognitoConfig": {
            "UserPool": "Pool_ID",
            "ClientId": "app-client-id"
        },
        "CreateDate": 1622151252.451,
        "Status": "Updating"
    }
}
```

導覽至 Amazon VPC 主控台。從左側面板選取**端點**。應刪除兩個 VPC 端點。

## 限制公開存取工作者入口網站，同時透過 VPC 維持存取權限
<a name="public-access-vpc"></a>

 VPC 或非 VPC 工作者入口網站中的工作者可以看到指派給他們的標籤工作。指派來自透過 OIDC 群組的工作團隊中的指派工作者。客戶有責任在其人力資源中設定 `sourceIpConfig`，限制對其公有工作者入口網站的存取。

**注意**  
您只能透過 SageMaker API 限制對工作者入口網站的存取。無法透過主控台來完成此選項。

使用下列命令來限制工作者入口網站的公有存取權限。

```
aws sagemaker update-workforce --region us-west-2 \
--workforce-name workforce-demo --source-ip-config '{"Cidrs":["10.0.0.0/16"]}'
```

在人力資源設定 `sourceIpConfig` 後，工作者可以存取 VPC 中的工作者入口網站，但不能透過公有網際網路存取。

**注意**  
您無法在 VPC 中對工作者入口網站設定 `sourceIP` 限制。