

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# エンドポイント設定を作成する
<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) を使用して作成された 1 つ以上のモデルを特定して、Amazon SageMaker AI がプロビジョンするリソースをデプロイします。`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)」を参照してください。

エンドポイントの可用性を向上させ、容量不足エラーを減らすには、本番稼働用バリアントで*インスタンスプール*を設定できます。インスタンスプールを使用すると、インスタンスタイプの順序付きリストを指定できるため、希望するインスタンスタイプが使用できない場合に SageMaker AI が自動的に優先度の低いタイプにフォールバックします。詳細については、「[インスタンスプールを使用して複数のインスタンスタイプにデプロイする](realtime-endpoints-heterogeneous.md)」を参照してください。

次の例では、 AWS SDK for Python (Boto3)を使用してエンドポイント設定を作成する方法を示します。

```
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 クライアントがモデルコンテナに送信する同時リクエストの最大数。