

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

# デバイス証明書があるデバイスのプロビジョニング
<a name="provision-w-cert"></a>

AWS IoT には、デバイスにデバイス証明書 (および関連するプライベートキー) が既にある場合にデバイスをプロビジョニングする 3 つの方法があります。
+ プロビジョニングテンプレートを使用した単一のモノのプロビジョニング。このオプションは、一度に 1 つずつデバイスをプロビジョニングするだけの場合に適しています。
+ デバイスを最初に接続するときにプロビジョニングするテンプレートを使用したJust-in-timeプロビジョニング (JITP) AWS IoT。このオプションは、大量のデバイスを登録する必要があるが、それらのデバイスに関して一括プロビジョニングリストにまとめることができる情報がない場合に適しています。
+ 一括登録。このオプションを使用すると、S3 バケットのファイルに保存された単一のモノのプロビジョニングテンプレートの値のリストを指定できます。このアプローチは、目的の特性をリストにまとめることができる、既知のデバイスが大量にある場合に適しています。

**Topics**
+ [単一のモノプロビジョニング](single-thing-provisioning.md)
+ [ジャストインタイムプロビジョニング](jit-provisioning.md)
+ [一括登録](bulk-provisioning.md)

# 単一のモノプロビジョニング
<a name="single-thing-provisioning"></a>

モノをプロビジョニングするには、[RegisterThing](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterThing.html) API または `register-thing` CLI コマンドを使用します。`register-thing` CLI コマンドは次の引数をとります。

--template-body  
プロビジョニングテンプレート｡

--parameters  
プロビジョニングテンプレートで使用される、JSON 形式のパラメータの名前/値のペアのリスト（例: `{"ThingName" : "MyProvisionedThing", "CSR" : "csr-text"}`）。

「[プロビジョニングテンプレート](provision-template.md)」を参照してください。

[RegisterThing](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterThing.html) または `register-thing` は、作成した証明書のリソースとテキストの ARN を返します。

```
{
    "certificatePem": "certificate-text",
    "resourceArns": {
    "PolicyLogicalName": "arn:aws:iot:us-west-2:123456789012:policy/2A6577675B7CD1823E271C7AAD8184F44630FFD7",
    "certificate": "arn:aws:iot:us-west-2:123456789012:cert/cd82bb924d4c6ccbb14986dcb4f40f30d892cc6b3ce7ad5008ed6542eea2b049",
    "thing": "arn:aws:iot:us-west-2:123456789012:thing/MyProvisionedThing"
    }
}
```

ディクショナリからパラメータを省略すると、デフォルト値が使用されます。デフォルト値が指定されていない場合、パラメータは値に置き換えられません。

# ジャストインタイムプロビジョニング
<a name="jit-provisioning"></a>

ジャストインタイムプロビジョニング (JITP) を使用して、デバイスが最初に AWS IoTに接続しようとするときにデバイスをプロビジョニングできます。デバイスをプロビジョニングするには、自動登録を有効にして、プロビジョニングテンプレートを、デバイス証明書に署名するために使用される CA 証明書に関連付ける必要があります。プロビジョニングの成功とエラーは、Amazon CloudWatch の [デバイスプロビジョニングのメトリクス](metrics_dimensions.md#provisioning-metrics) と同様にログに記録されます。

**Topics**
+ [JITP の概要](#jit-provisioning-overview)
+ [プロビジョニングテンプレートを使用して CA を登録する](#jit-provisioning-registerCA-template)
+ [プロビジョニングテンプレート名を使用して CA を登録する](#jit-provisioning-registerCA-templateName)

## JITP の概要
<a name="jit-provisioning-overview"></a>

登録された CA 証明書によって署名された証明書 AWS IoT を使用してデバイスが に接続しようとすると、 は CA 証明書からテンプレートを AWS IoT ロードし、それを使用して [RegisterThing](fleet-provision-api.md#register-thing) を呼び出します。JITP ワークフローは、最初に `PENDING_ACTIVATION` というステータス値で証明書を登録します。デバイスのプロビジョニングフローが完了すると、証明書のステータスは `ACTIVE` に変わります。

AWS IoT は、プロビジョニングテンプレートで宣言および参照できる以下のパラメータを定義します。
+ `AWS::IoT::Certificate::Country`
+ `AWS::IoT::Certificate::Organization`
+ `AWS::IoT::Certificate::OrganizationalUnit`
+ `AWS::IoT::Certificate::DistinguishedNameQualifier`
+ `AWS::IoT::Certificate::StateName`
+ `AWS::IoT::Certificate::CommonName`
+ `AWS::IoT::Certificate::SerialNumber`
+ `AWS::IoT::Certificate::Id`

これらのプロビジョニングテンプレートパラメータの値は、プロビジョニング対象のデバイスの証明書の件名フィールドから JITP が抽出できるものに限られます。証明書には、テンプレート本体のすべてのパラメータの値が含まれている必要があります。`AWS::IoT::Certificate::Id` パラメータは、証明書に含まれている ID ではなく、内部で生成された ID を参照します。この ID の値は、 AWS IoT ルール内の `principal()`関数を使用して取得できます。

**注記**  
デバイスの最初の接続で信頼チェーン全体を送信しなくても、ジャ AWS IoT Core just-in-timeプロビジョニング (JITP) 機能を使用してデバイスをプロビジョニングできます AWS IoT Core。CA 証明書の提示はオプションですが、デバイスが AWS IoT Coreに接続するときに [[Server Name Indication (SNI)]](https://datatracker.ietf.org/doc/html/rfc3546#section-3.1) (サーバーネームインディケーション (SNI)) エクステンションを送信する必要があります。

### テンプレート本文の例
<a name="jit-provisioning-example-templatebody"></a>

次の JSON ファイルは、完全な JITP テンプレートのテンプレート本文の例です。

```
{
   "Parameters":{
      "AWS::IoT::Certificate::CommonName":{
         "Type":"String"
      },
      "AWS::IoT::Certificate::SerialNumber":{
         "Type":"String"
      },
      "AWS::IoT::Certificate::Country":{
         "Type":"String"
      },
      "AWS::IoT::Certificate::Id":{
         "Type":"String"
      }
   },
   "Resources":{
      "thing":{
         "Type":"AWS::IoT::Thing",
         "Properties":{
            "ThingName":{
               "Ref":"AWS::IoT::Certificate::CommonName"
            },
            "AttributePayload":{
               "version":"v1",
               "serialNumber":{
                  "Ref":"AWS::IoT::Certificate::SerialNumber"
               }
            },
            "ThingTypeName":"lightBulb-versionA",
            "ThingGroups":[
               "v1-lightbulbs",
               {
                  "Ref":"AWS::IoT::Certificate::Country"
               }
            ]
         },
         "OverrideSettings":{
            "AttributePayload":"MERGE",
            "ThingTypeName":"REPLACE",
            "ThingGroups":"DO_NOTHING"
         }
      },
      "certificate":{
         "Type":"AWS::IoT::Certificate",
         "Properties":{
            "CertificateId":{
               "Ref":"AWS::IoT::Certificate::Id"
            },
            "Status":"ACTIVE"
         }
      },
      "policy":{
         "Type":"AWS::IoT::Policy",
         "Properties":{
            "PolicyDocument":"{ \"Version\": \"2012-10-17\",		 	 	  \"Statement\": [{ \"Effect\": \"Allow\", \"Action\":[\"iot:Publish\"], \"Resource\": [\"arn:aws:iot:us-east-1:123456789012:topic/foo/bar\"] }] }"
         }
      }
   }
}
```

このサンプルテンプレートでは、証明書から抽出され、`AWS::IoT::Certificate::CommonName` セクションで使用されている `AWS::IoT::Certificate::SerialNumber`、`AWS::IoT::Certificate::Country`、`AWS::IoT::Certificate::Id` および `Resources` プロビジョニングパラメータの値を宣言します。次に、JITP ワークフローはこのテンプレートを使用して次のアクションを実行します。
+ 証明書を登録し、そのステータスを PENDING\$1ACTIVE に設定します。
+ 1 つのモノのリソースを作成します。
+ 1 つのポリシーのリソースを作成します。
+ ポリシーを証明書にアタッチします。
+ 証明書をモノにアタッチします。
+ 証明書のステータスを ACTIVE に更新します。

`templateBody` の `Parameters` セクションに記載されているすべてのプロパティが証明書に含まれていない場合、デバイスのプロビジョニングは失敗します。例えば、`AWS::IoT::Certificate::Country` がテンプレートに含まれていても、証明書に `Country` プロパティがない場合、デバイスのプロビジョニングは失敗します。

CloudTrail を使用して、JITP テンプレートに関する問題をトラブルシューティングすることもできます。Amazon CloudWatch にログ記録されるメトリクスについては、「[デバイスプロビジョニングのメトリクス](metrics_dimensions.md#provisioning-metrics)」を参照してください。プロビジョニングテンプレートの詳細については、「[プロビジョニングテンプレート](provision-template.md)」を参照してください。

**注記**  
プロビジョニングプロセス中に、just-in-timeプロビジョニング (JITP) は他の AWS IoT コントロールプレーン API オペレーションを呼び出します。これらの呼び出しは、アカウントに設定された[AWS IoT スロットリングクォータ](https://docs.aws.amazon.com/general/latest/gr/iot-core.html#throttling-limits)を超過し、スロットリングされた呼び出しが発生する可能性があります。必要に応じて、[AWS カスタマーサポート](https://console.aws.amazon.com/support/home)に連絡して、スロットリングのクォータを引き上げてください。

## プロビジョニングテンプレートを使用して CA を登録する
<a name="jit-provisioning-registerCA-template"></a>

完全なプロビジョニングテンプレートを使用して CA を登録するには、次の手順に従います。

1. 次の例に示すようなプロビジョニングテンプレートとロール ARN 情報を JSON ファイルとして保存します。

   ```
   { 
        "templateBody" : "{\r\n    \"Parameters\" : {\r\n        \"AWS::IoT::Certificate::CommonName\": {\r\n            \"Type\": \"String\"\r\n        },\r\n        \"AWS::IoT::Certificate::SerialNumber\": {\r\n            \"Type\": \"String\"\r\n        },\r\n        \"AWS::IoT::Certificate::Country\": {\r\n            \"Type\": \"String\"\r\n        },\r\n        \"AWS::IoT::Certificate::Id\": {\r\n            \"Type\": \"String\"\r\n        }\r\n    },\r\n    \"Resources\": {\r\n        \"thing\": {\r\n            \"Type\": \"AWS::IoT::Thing\",\r\n            \"Properties\": {\r\n                \"ThingName\": {\r\n                    \"Ref\": \"AWS::IoT::Certificate::CommonName\"\r\n                },\r\n                \"AttributePayload\": {\r\n                    \"version\": \"v1\",\r\n                    \"serialNumber\": {\r\n                        \"Ref\": \"AWS::IoT::Certificate::SerialNumber\"\r\n                    }\r\n                },\r\n                \"ThingTypeName\": \"lightBulb-versionA\",\r\n                \"ThingGroups\": [\r\n                    \"v1-lightbulbs\",\r\n                    {\r\n                        \"Ref\": \"AWS::IoT::Certificate::Country\"\r\n                    }\r\n                ]\r\n            },\r\n            \"OverrideSettings\": {\r\n                \"AttributePayload\": \"MERGE\",\r\n                \"ThingTypeName\": \"REPLACE\",\r\n                \"ThingGroups\": \"DO_NOTHING\"\r\n            }\r\n        },\r\n        \"certificate\": {\r\n            \"Type\": \"AWS::IoT::Certificate\",\r\n            \"Properties\": {\r\n                \"CertificateId\": {\r\n                    \"Ref\": \"AWS::IoT::Certificate::Id\"\r\n                },\r\n                \"Status\": \"ACTIVE\"\r\n            },\r\n            \"OverrideSettings\": {\r\n                \"Status\": \"DO_NOTHING\"\r\n            }\r\n        },\r\n        \"policy\": {\r\n            \"Type\": \"AWS::IoT::Policy\",\r\n            \"Properties\": {\r\n                \"PolicyDocument\": \"{ \\\"Version\\\": \\\"2012-10-17		 	 	 \\\", \\\"Statement\\\": [{ \\\"Effect\\\": \\\"Allow\\\", \\\"Action\\\":[\\\"iot:Publish\\\"], \\\"Resource\\\": [\\\"arn:aws:iot:us-east-1:123456789012:topic\/foo\/bar\\\"] }] }\"\r\n            }\r\n        }\r\n    }\r\n}",
        "roleArn" : "arn:aws:iam::123456789012:role/JITPRole"
   }
   ```

   この例で、`templateBody` フィールドの値は、エスケープ文字列として指定された JSON オブジェクトである必要があり、[前のリスト](#jit-provisioning-overview)に示した値のみを使用できます。`json.dumps` (Python) や `JSON.stringify` （ノード）など、必要な JSON 出力を作成するには、さまざまなツールを使用できます。`roleARN` フィールドの値は、`AWSIoTThingsRegistration` がアタッチされたロールの ARN である必要があります。また、テンプレートでは例のインライン `PolicyName` の代わりに、既存の `PolicyDocument` を使用できます 

1. [RegisterCACertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCACertificate.html) API オペレーションまたは [https://docs.aws.amazon.com//cli/latest/reference/iot/register-ca-certificate.html](https://docs.aws.amazon.com//cli/latest/reference/iot/register-ca-certificate.html) CLI コマンドを使用して CA 証明書を登録します。前のステップで保存したプロビジョニングテンプレートとロール ARN 情報のディレクトリを指定します。

   以下に、 AWS CLIを使用して `DEFAULT` モードで CA 証明書を登録する方法の例を示します。

   ```
   aws iot register-ca-certificate --ca-certificate file://your-ca-cert --verification-cert file://your-verification-cert 
                   --set-as-active --allow-auto-registration --registration-config file://your-template
   ```

   以下に、 AWS CLIを使用して `SNI_ONLY` モードで CA 証明書を登録する方法の例を示します。

   ```
   aws iot register-ca-certificate --ca-certificate file://your-ca-cert --certificate-mode SNI_ONLY
                    --set-as-active --allow-auto-registration --registration-config file://your-template
   ```

   詳細については､「[Register your CA Certificates](https://docs.aws.amazon.com//iot/latest/developerguide/register-CA-cert.html)」(CA 証明書の登録) を参照してください。

1.  (オプション) [UpdateCACertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_UpdateCACertificate.html) API オペレーションまたは [https://docs.aws.amazon.com//cli/latest/reference/iot/update-ca-certificate.html](https://docs.aws.amazon.com//cli/latest/reference/iot/update-ca-certificate.html) CLI コマンドを使用して、CA 証明書の設定を更新します。

    AWS CLIを使用して CA 証明書を更新する方法の例を次に示します。

   ```
   aws iot update-ca-certificate --certificate-id caCertificateId
                   --new-auto-registration-status ENABLE --registration-config file://your-template
   ```

## プロビジョニングテンプレート名を使用して CA を登録する
<a name="jit-provisioning-registerCA-templateName"></a>

プロビジョニングテンプレート名を使用して CA を登録するには、次の手順に従います。

1. プロビジョニングテンプレート本文を JSON ファイルとして保存します。テンプレート本文の例は「[テンプレート本文の例](#jit-provisioning-example-templatebody)」にあります。

1. プロビジョニングテンプレートを作成するには、[CreateProvisioningTemplate](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateProvisioningTemplate.html) API または [https://docs.aws.amazon.com//cli/latest/reference/iot/create-provisioning-template.html](https://docs.aws.amazon.com//cli/latest/reference/iot/create-provisioning-template.html)CLI コマンドを使用します。

   ```
   aws iot create-provisioning-template --template-name your-template-name \
           --template-body file://your-template-body.json --type JITP \
           --provisioning-role-arn arn:aws:iam::123456789012:role/test
   ```
**注記**  
ジャストインタイムプロビジョニング (JITP) の場合は、プロビジョニングテンプレートを作成するときにテンプレートタイプとして `JITP` を指定する必要があります｡ テンプレートタイプの詳細については、「*AWS API リファレンス*」の「[CreateProvisioningTemplate](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateProvisioningTemplate.html)」を参照してください。

1. CA をテンプレート名で登録するには、[RegisterCACertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCACertificate.html) API または [https://docs.aws.amazon.com//cli/latest/reference/iot/register-ca-certificate.html](https://docs.aws.amazon.com//cli/latest/reference/iot/register-ca-certificate.html) CLI コマンドを使用します。

   ```
   aws iot register-ca-certificate --ca-certificate file://your-ca-cert --verification-cert file://your-verification-cert \
           --set-as-active --allow-auto-registration --registration-config templateName=your-template-name
   ```

# 一括登録
<a name="bulk-provisioning"></a>

[https://docs.aws.amazon.com/iot/latest/apireference/API_StartThingRegistrationTask.html](https://docs.aws.amazon.com/iot/latest/apireference/API_StartThingRegistrationTask.html) コマンドを使用して、モノを一括で登録できます。このコマンドは、プロビジョニングテンプレート、S3 バケット名、キー名、ロール ARN (S3 バケット内のファイルへのアクセスを許可する) を使用します。S3 バケットのファイルには、テンプレート内のパラメータを置き換えるために使用される値が含まれています。このファイルは､改行で区切られた JSON ファイルでなければなりません。各行には、単一のデバイスを登録するためのすべてのパラメータ値が含まれています。例: 

```
{"ThingName": "foo", "SerialNumber": "123", "CSR": "csr1"}
{"ThingName": "bar", "SerialNumber": "456", "CSR": "csr2"}
```

以下の一括登録関連の API オペレーションが役立つ場合があります。
+ [ListThingRegistrationTasks](https://docs.aws.amazon.com/iot/latest/apireference/API_ListThingRegistrationTasks.html): 現在のモノの一括プロビジョニングタスクを一覧表示します。
+ [DescribeThingRegistrationTask](https://docs.aws.amazon.com/iot/latest/apireference/API_DescribeThingRegistrationTask.html): 特定のモノの一括登録タスクに関する情報を提供します。
+ [StopThingRegistrationTask](https://docs.aws.amazon.com/iot/latest/apireference/API_StopThingRegistrationTask.html): 一括登録タスクを停止します。
+ [ListThingRegistrationTaskReports](https://docs.aws.amazon.com/iot/latest/apireference/API_ListThingRegistrationTaskReports.html): モノの一括登録タスクの結果、失敗、またはその両方を確認するために使用されます。

**注記**  
一度に実行できる一括登録オペレーションタスクは、（アカウントごとに） 1 つだけです。
一括登録オペレーションは、他の AWS IoT コントロールプレーン API オペレーションを呼び出します。これらの呼び出しは、アカウントの [AWS IoT スロットリングクォータ](https://docs.aws.amazon.com/general/latest/gr/iot-core.html#throttling-limits)を超過し、スロットルエラーが発生する可能性があります。必要に応じて、[AWS カスタマーサポート](https://console.aws.amazon.com/support/home)に連絡して AWS IoT スロットリングクォータを引き上げます。