

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

# 非同期エンドポイントを呼び出す
<a name="async-inference-invoke-endpoint"></a>

`InvokeEndpointAsync` を使用して非同期エンドポイントでホストされているモデルから推論を取得します。

**注記**  
まだ行っていない場合、推論データ (機械学習モデル、サンプルデータなど) を Amazon S3 にアップロードします。

リクエストペイロードは、2 つの方法のいずれかで指定できます。これらのオプションは相互に排他的です。リクエストで厳密に 1 つ指定します。
+ **インラインペイロード** — 最大 128,000 バイトのペイロードの場合、 `Body`パラメータを使用してデータをリクエストに直接渡します。これにより、各呼び出しの前にペイロードが Amazon S3 にアップロードされるのを回避できます。
+ **Amazon S3 の場所** — より大きなペイロードの場合は、推論データを Amazon S3 にアップロードし、その URI に `InputLocation`パラメータを渡します。

リクエストに次のフィールドを指定してください。
+ の場合`Body`、推論ペイロードをインラインで指定します (最大 128,000 バイト）。この *または* を使用しますが`InputLocation`、両方は使用しません。
+ には`InputLocation`、推論データの Amazon S3 の場所を指定します。この *または* を使用しますが`Body`、両方は使用しません。
+ `EndpointName` には、エンドポイントの名前を指定します。
+ (オプション) `InvocationTimeoutSeconds` では、リクエストの最大タイムアウトを設定できます。この値は、1 回のリクエスト当たり最大 3600 秒 (1 時間) に設定できます。リクエストにこのフィールドを指定しない場合、デフォルトではリクエストは 15 分でタイムアウトします。

次の例では、 `Body`パラメータを使用してペイロードをインラインで送信します。このパラメータでは、最初に入力を Amazon S3 にアップロードする必要はありません。

```
# Create a low-level client representing Amazon SageMaker Runtime
sagemaker_runtime = boto3.client("sagemaker-runtime", region_name={{<aws_region>}})

# Specify the inference payload inline (up to 128,000 bytes)
payload = {{b'{"inputs": "your inference data here"}'}}

# The name of the endpoint. The name must be unique within an AWS リージョン in your AWS アカウント.
endpoint_name={{'<endpoint-name>'}}

# After you deploy a model into production using SageMaker AI hosting
# services, your client applications use this API to get inferences
# from the model hosted at the specified endpoint.
response = sagemaker_runtime.invoke_endpoint_async(
                            EndpointName=endpoint_name,
                            Body=payload,
                            ContentType={{"application/json"}},
                            InvocationTimeoutSeconds=3600)
```

または、ペイロードを Amazon S3 に保存し、その場所を `InputLocation`パラメータで渡すこともできます。まだ行っていない場合は、エンドポイントを呼び出す前に推論データを Amazon S3 にアップロードします。

```
# Create a low-level client representing Amazon SageMaker Runtime
sagemaker_runtime = boto3.client("sagemaker-runtime", region_name={{<aws_region>}})

# Specify the location of the input. Here, a single SVM sample
input_location = {{"s3://bucket-name/test_point_0.libsvm"}}

# The name of the endpoint. The name must be unique within an AWS リージョン in your AWS アカウント. 
endpoint_name={{'<endpoint-name>'}}

# After you deploy a model into production using SageMaker AI hosting 
# services, your client applications use this API to get inferences 
# from the model hosted at the specified endpoint.
response = sagemaker_runtime.invoke_endpoint_async(
                            EndpointName=endpoint_name, 
                            InputLocation=input_location,
                            InvocationTimeoutSeconds=3600)
```

JSON 文字列としてレスポンスを受け取ります。これには、リクエスト ID と、処理後に API コールに対するレスポンスを受ける Amazon S3 バケット名が含まれます。