

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

# 建立多容器端點 (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) API，來建立多容器端點，方法就如同建立任何其他端點一樣。您可以循序執行這些容器作為推論管道，或使用直接調用來執行每個個別的容器。多容器端點在您呼叫 `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)。