

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 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` 限制。