

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

# 创建端点配置
<a name="async-inference-create-endpoint-create-endpoint-config"></a>

拥有模型后，请使用 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpointConfig.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpointConfig.html) 创建端点配置。Amazon SageMaker AI 托管服务使用此配置来部署模型。在配置中，您可以标识使用和创建的一个或多个模型 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModel.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModel.html)，以部署您希望 Amazon A SageMaker I 预配置的资源。指定 `AsyncInferenceConfig` 对象并为 `OutputConfig` 提供输出 Amazon S3 位置。您可以选择指定 [Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) 主题，在其上发送有关预测结果的通知。有关 Amazon SNS 主题的更多信息，请参阅[配置 Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/sns-configuring.html)。

以下示例演示了如何使用 适用于 Python (Boto3) 的 AWS SDK创建端点配置:

```
import datetime
from time import gmtime, strftime

# Create an endpoint config name. Here we create one based on the date  
# so it we can search endpoints based on creation time.
endpoint_config_name = f"XGBoostEndpointConfig-{strftime('%Y-%m-%d-%H-%M-%S', gmtime())}"

# The name of the model that you want to host. This is the name that you specified when creating the model.
model_name='<The_name_of_your_model>'

create_endpoint_config_response = sagemaker_client.create_endpoint_config(
    EndpointConfigName=endpoint_config_name, # You will specify this name in a CreateEndpoint request.
    # List of ProductionVariant objects, one for each model that you want to host at this endpoint.
    ProductionVariants=[
        {
            "VariantName": "variant1", # The name of the production variant.
            "ModelName": model_name, 
            "InstanceType": "ml.m5.xlarge", # Specify the compute instance type.
            "InitialInstanceCount": 1 # Number of instances to launch initially.
        }
    ],
    AsyncInferenceConfig={
        "OutputConfig": {
            # Location to upload response outputs when no location is provided in the request.
            "S3OutputPath": f"s3://{s3_bucket}/{bucket_prefix}/output"
            # (Optional) specify Amazon SNS topics
            "NotificationConfig": {
                "SuccessTopic": "arn:aws:sns:aws-region:account-id:topic-name",
                "ErrorTopic": "arn:aws:sns:aws-region:account-id:topic-name",
            }
        },
        "ClientConfig": {
            # (Optional) Specify the max number of inflight invocations per instance
            # If no value is provided, Amazon SageMaker will choose an optimal value for you
            "MaxConcurrentInvocationsPerInstance": 4
        }
    }
)

print(f"Created EndpointConfig: {create_endpoint_config_response['EndpointConfigArn']}")
```

在上述示例中，您为 `AsyncInferenceConfig` 字段的 `OutputConfig` 指定以下键：
+ `S3OutputPath`：请求中没有提供位置时，将响应输出上传到的位置。
+ `NotificationConfig`:（可选）推理请求成功 (`SuccessTopic`) 或者失败 (`ErrorTopic`) 时向您发布通知的 SNS 主题。

您还可以在 `AsyncInferenceConfig` 字段中为 `ClientConfig` 指定以下可选参数：
+ `MaxConcurrentInvocationsPerInstance`:（可选） SageMaker AI 客户端向模型容器发送的最大并发请求数。