

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

# 通过直接调用来调用多容器端点
<a name="multi-container-direct"></a>

SageMaker AI 多容器端点使客户能够部署多个容器，以便在 SageMaker AI 终端节点上部署不同的模型。您最多可以在单个端点上托管 15 个不同的推理容器。通过使用直接调用，您可以向托管在多容器端点上的特定推理容器发送请求。

 要通过直接调用来调用多容器端点，请像调用任何其他端点一样调用 [invoke\$1endpoint](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker-runtime.html#SageMakerRuntime.Client.invoke_endpoint)，并使用 `TargetContainerHostname` 参数指定要调用的容器。

 

 以下示例直接调用多容器端点的 `secondContainer` 以获得预测。

```
import boto3
runtime_sm_client = boto3.Session().client('sagemaker-runtime')

response = runtime_sm_client.invoke_endpoint(
   EndpointName ='my-endpoint',
   ContentType = 'text/csv',
   TargetContainerHostname='secondContainer', 
   Body = body)
```

 对于向多容器端点发出的每个直接调用请求，只有具有 `TargetContainerHostname` 的容器才会处理调用请求。如果执行以下任一操作，都会收到验证错误：
+ 指定端点中不存在的 `TargetContainerHostname`
+ 不要在向配置为直接调用的端点发出的请求中指定 `TargetContainerHostname` 的值
+ 在向未配置为直接调用的端点发出的请求中指定 `TargetContainerHostname` 的值。