

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

# 创建多容器端点 (Boto 3)
<a name="multi-container-create"></a>

通过调用[CreateModel](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModel.html)、和来创建多容器终端节点 [CreateEndpointConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpointConfig.html)，[CreateEndpoint](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpoint.html) APIs 就像创建任何其他端点一样。您可以将这些容器作为推理管线按顺序运行它们，也可以使用直接调用来运行各个单独的容器。当您调用 `create_model` 时，多容器端点需要满足以下要求：
+ 使用 `Containers` 参数代替 `PrimaryContainer`，并在 `Containers` 参数中包含多个容器。
+ 直接调用的多容器端点中的每个容器都需要 `ContainerHostname` 参数。
+ 将 `InferenceExecutionConfig` 字段的 `Mode` 参数设置为 `Direct` 以直接调用每个容器，或者设置为 `Serial` 以将容器用作推理管线。默认模式为 `Serial`。

**注意**  
目前，多容器端点最多支持 15 个容器。

以下示例创建了用于直接调用的多容器模型。

1. 创建容器元素，且 `InferenceExecutionConfig` 为直接调用。

   ```
   container1 = {
                    'Image': '123456789012.dkr.ecr.us-east-1.amazonaws.com/myimage1:mytag',
                    'ContainerHostname': 'firstContainer'
                }
   
   container2 = {
                    'Image': '123456789012.dkr.ecr.us-east-1.amazonaws.com/myimage2:mytag',
                    'ContainerHostname': 'secondContainer'
                }
   inferenceExecutionConfig = {'Mode': 'Direct'}
   ```

1. 使用容器元素创建模型并设置 `InferenceExecutionConfig` 字段。

   ```
   import boto3
   sm_client = boto3.Session().client('sagemaker')
   
   response = sm_client.create_model(
                  ModelName = 'my-direct-mode-model-name',
                  InferenceExecutionConfig = inferenceExecutionConfig,
                  ExecutionRoleArn = role,
                  Containers = [container1, container2]
              )
   ```

要创建端点，则要调用 [create\$1endpoint\$1config](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_endpoint_config) 和 [create\$1endpoint](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_endpoint)，这和创建任何其他端点一样。