

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

# を使用してコンパイル済みモデルをデプロイする AWS CLI
<a name="neo-deployment-hosting-services-cli"></a>

モデルが または Amazon SageMaker AI コンソールを使用してコンパイルされている場合は AWS SDK for Python (Boto3) AWS CLI、[前提条件](https://docs.aws.amazon.com//sagemaker/latest/dg/neo-deployment-hosting-services-prerequisites)セクションを満たす必要があります。[AWS CLI](https://docs.aws.amazon.com/cli/latest/reference/) を使って SageMaker Neo コンパイルのモデルを作成してデプロイするには、次のステップを実行します。

**Topics**
+ [モデルをデプロイする](#neo-deploy-cli)

## モデルをデプロイする
<a name="neo-deploy-cli"></a>

[ 前提条件](https://docs.aws.amazon.com//sagemaker/latest/dg/neo-deployment-hosting-services-prerequisites)を満たしたら、`create-model`、、`create-enpoint-config`および `create-endpoint` AWS CLI コマンドを使用します。次のステップでは、これらのコマンドを使って Neo コンパイル済みモデルをデプロイする方法を説明します。



### モデルを作成する
<a name="neo-deployment-hosting-services-cli-create-model"></a>

[Neo の推論コンテナイメージ](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-deployment-hosting-services-container-images.html)で、推論イメージの URI を選択し、`create-model` API を使って SageMaker AI モデルを作成します。これは 2 つのステップで行えます。

1. `create_model.json` ファイルを作成します。ファイル内で、モデルの名前、イメージ URI、Amazon S3 バケットにある `model.tar.gz` ファイルへのパス、SageMaker AI 実行ロールを指定します。

   ```
   {
       "ModelName": {{"insert model name"}},
       "PrimaryContainer": {
           "Image": {{"insert the ECR Image URI"}},
           "ModelDataUrl": {{"insert S3 archive URL"}},
           "Environment": {{{"See details below"}}}
       },
       "ExecutionRoleArn": {{"ARN for AmazonSageMaker-ExecutionRole"}}
   }
   ```

   SageMaker AI を使ってモデルをトレーニングした場合は、次の環境変数を指定します。

   ```
   "Environment": {
       "SAGEMAKER_SUBMIT_DIRECTORY" : {{"[Full S3 path for *.tar.gz file containing the training script]"}}
   }
   ```

   SageMaker AI を使ってモデルをトレーニングしなかった場合は、次の環境変数を指定します。

------
#### [ MXNet and PyTorch ]

   ```
   "Environment": {
       "SAGEMAKER_PROGRAM": "inference.py",
       "SAGEMAKER_SUBMIT_DIRECTORY": {{"/opt/ml/model/code"}},
       "SAGEMAKER_CONTAINER_LOG_LEVEL": "20",
       "SAGEMAKER_REGION": {{"insert your region"}},
       "MMS_DEFAULT_RESPONSE_TIMEOUT": "500"
   }
   ```

------
#### [ TensorFlow ]

   ```
   "Environment": {
       "SAGEMAKER_PROGRAM": "inference.py",
       "SAGEMAKER_SUBMIT_DIRECTORY": {{"/opt/ml/model/code"}},
       "SAGEMAKER_CONTAINER_LOG_LEVEL": "20",
       "SAGEMAKER_REGION": {{"insert your region"}}
   }
   ```

------
**注記**  
`AmazonSageMaker-ExecutionRole` IAM ロールに `AmazonSageMakerFullAccess` ポリシーと `AmazonS3ReadOnlyAccess` ポリシーをアタッチする必要があります。

1. 次のコマンドを実行します。

   ```
   aws sagemaker create-model --cli-input-json file://create_model.json
   ```

   `create-model` API の完全な構文については、「[https://docs.aws.amazon.com/cli/latest/reference/sagemaker/create-model.html](https://docs.aws.amazon.com/cli/latest/reference/sagemaker/create-model.html)」を参照してください。

### エンドポイント設定を作成する
<a name="neo-deployment-hosting-services-cli-create-endpoint-config"></a>

SageMaker AI モデルを作成したら、`create-endpoint-config` API を使ってエンドポイント設定を作成します。これを行うには、エンドポイント設定の仕様を使って JSON ファイルを作成します。例として次のコードテンプレートを使い、`create_config.json` と名付けて保存します。

```
{
    "EndpointConfigName": {{"<provide your endpoint config name>"}},
    "ProductionVariants": [
        {
            "VariantName": {{"<provide your variant name>"}},
            "ModelName": "my-sagemaker-model",
            "InitialInstanceCount": 1,
            "InstanceType": {{"<provide your instance type here>"}},
            "InitialVariantWeight": 1.0
        }
    ]
}
```

次に、次の AWS CLI コマンドを実行してエンドポイント設定を作成します。

```
aws sagemaker create-endpoint-config --cli-input-json file://create_config.json
```

`create-endpoint-config` API の完全な構文については、「[https://docs.aws.amazon.com/cli/latest/reference/sagemaker/create-endpoint-config.html](https://docs.aws.amazon.com/cli/latest/reference/sagemaker/create-endpoint-config.html)」を参照してください。

### エンドポイントの作成
<a name="neo-deployment-hosting-services-cli-create-endpoint"></a>

エンドポイント設定を作成したら、`create-endpoint` API を使ってエンドポイントを作成します。: 

```
aws sagemaker create-endpoint --endpoint-name {{'<provide your endpoint name>'}} --endpoint-config-name {{'<insert your endpoint config name>'}}
```

`create-endpoint` API の完全な構文については、「[https://docs.aws.amazon.com/cli/latest/reference/sagemaker/create-endpoint.html](https://docs.aws.amazon.com/cli/latest/reference/sagemaker/create-endpoint.html)」を参照してください。