

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

# コンポーネント設定の更新
<a name="update-component-configurations"></a>

コンポーネント設定は、各コンポーネントのパラメータを定義する JSON オブジェクトです。各コンポーネントの recipe は、コアデバイスにコンポーネントをデプロイするときに変更するデフォルト設定を定義します。

デプロイを作成するとき、各コンポーネントに適用する設定の更新を指定できます。設定の更新はパッチ操作であり、更新がコアデバイスに存在するコンポーネント設定を修正することを意味します。コアデバイスにコンポーネントがない場合、設定更新がそのデプロイのデフォルト設定を修正して適用します。

設定更新は、リセット更新とマージ更新を定義します。リセット更新は、デフォルトにリセットまたは削除する設定値を定義します。マージ更新は、コンポーネントに設定する新しい設定値を定義します。設定更新をデプロイすると、 AWS IoT Greengrass Core ソフトウェアはマージ更新の前にリセット更新を実行します。

コンポーネントは、デプロイする設定更新を検証できます。コンポーネントは、デプロイが設定を変更した際に通知を受信するようにサブスクライブして、サポートしていない設定を拒否できます。詳細については、「[コンポーネント設定とやり取り](ipc-component-configuration.md)」を参照してください。

**Topics**
+ [更新のリセット](#reset-configuration-update)
+ [マージの更新](#merge-configuration-update)
+ [例](#configuration-update-example)

## 更新のリセット
<a name="reset-configuration-update"></a>

リセット更新は、コアデバイスでデフォルトにリセットする設定値を定義します。設定値にデフォルト値がない場合、リセット更新がコンポーネントの設定からその値を削除します。これにより、無効な設定によって破損するコンポーネントを修正するうえで役立ちます。

JSON ポインタのリストを使用して、リセットする設定値を定義します。JSON ポインタはフォワードスラッシュ (`/`) で始まります。ネストされたコンポーネント設定の値を識別するには、フォワードスラッシュ (`/`) を使用して、設定の各レベルのキーを区切ります。詳細については、「[JSON ポインタの仕様](https://tools.ietf.org/html/rfc6901)」を参照してください。

**注記**  
リスト全体のみをデフォルト値にリセットできます。更新リセットを使用して、リストの個々の要素をリセットすることはできません。

コンポーネントの設定を全体的にデフォルト値にリセットするには、リセット更新として空の文字列を 1 つ指定します。

```
"reset": [""]
```

## マージの更新
<a name="merge-configuration-update"></a>

マージ更新は、コアのコンポーネント設定に挿入する設定値を定義します。マージ更新は、リセット更新で指定したパスの値をリセットした後に AWS IoT Greengrass Core ソフトウェアがマージする JSON オブジェクトです。 AWS CLI または AWS SDKs を使用する場合は、この JSON オブジェクトを文字列としてシリアル化する必要があります。

コンポーネントのデフォルト設定に存在しないキー値のペアをマージできます。同じキーの値とは異なるタイプのキー値のペアをマージすることもできます。古い値は新しい値により上書きされます。つまり、設定オブジェクトの構造を変更できます。

Null 値を空の文字列、リスト、オブジェクトとマージできます。

**注記**  
マージ更新は、リストに要素の挿入または追加する目的として使用することはできません。リスト全体を置き換え、あるいは各要素に一意のキーを持つオブジェクトを定義できます。  
<a name="configuration-value-type-note"></a>AWS IoT Greengrass は設定値に JSON を使用します。JSON は数値タイプを指定しますが、整数と浮動小数点数を区別しません。その結果、 AWS IoT Greengrassで設定値が浮動小数点数に変換されることがあります。コンポーネントが正しいデータタイプを使用することを確認するには、数値の設定値を文字列として定義することをお勧めします。次に、整数または浮動小数点としてコンポーネントでパースします。これにより、設定値が設定とコアデバイスに対して同じタイプであることを保証します。

### マージ更新で recipe 変数を使用する
<a name="merge-configuration-update-recipe-variables"></a>

この機能は、[Greengrass nucleus コンポーネント](greengrass-nucleus-component.md)の v2.6.0 以降で利用できます。

Greengrass nucleus の [interpolateComponentConfiguration](greengrass-nucleus-component.md#greengrass-nucleus-component-configuration-interpolate-component-configuration) 設定オプションを `true` に設定したら、マージ更新で `component_dependency_name:configuration:json_pointer` recipe 変数以外の recipe 変数を使用できます。たとえば、マージ更新で `{iot:thingName}` recipe 変数を使用して、[プロセス間通信 (IPC) 認可ポリシー](interprocess-communication.md#ipc-authorization-policies)などのコンポーネント設定値にコアデバイスの AWS IoT モノの名前を含めることができます。

## 例
<a name="configuration-update-example"></a>

次の例では、次のデフォルト設定を持つダッシュボードコンポーネントの設定更新を示しています。このコンポーネントの例は、産業機器に関する情報を表示します。

```
{
  "name": null,
  "mode": "REQUEST",
  "network": {
    "useHttps": true,
    "port": {
      "http": 80,
      "https": 443
    },
  },
  "tags": []
}
```

### 産業用ダッシュボード コンポーネント recipe
<a name="w2ab1c24c25c22c16c17b7b1"></a>

------
#### [ JSON ]

```
{
  "RecipeFormatVersion": "2020-01-25",
  "ComponentName": "com.example.IndustrialDashboard",
  "ComponentVersion": "1.0.0",
  "ComponentDescription": "Displays information about industrial equipment.",
  "ComponentPublisher": "Amazon",
  "ComponentConfiguration": {
    "DefaultConfiguration": {
      "name": null,
      "mode": "REQUEST",
      "network": {
        "useHttps": true,
        "port": {
          "http": 80,
          "https": 443
        },
      },
      "tags": []
    }
  },
  "Manifests": [
    {
      "Platform": {
        "os": "linux"
      },
      "Lifecycle": {
        "Run": "python3 -u {artifacts:path}/industrial_dashboard.py"
      }
    },
    {
      "Platform": {
        "os": "windows"
      },
      "Lifecycle": {
        "Run": "py -3 -u {artifacts:path}/industrial_dashboard.py"
      }
    }
  ]
}
```

------
#### [ YAML ]

```
---
RecipeFormatVersion: '2020-01-25'
ComponentName: com.example.IndustrialDashboard
ComponentVersion: '1.0.0'
ComponentDescription: Displays information about industrial equipment.
ComponentPublisher: Amazon
ComponentConfiguration:
  DefaultConfiguration:
    name: null
    mode: REQUEST
    network:
      useHttps: true
      port:
        http: 80
        https: 443
    tags: []
Manifests:
  - Platform:
      os: linux
    Lifecycle:
      Run: |
        python3 -u {artifacts:path}/industrial_dashboard.py
  - Platform:
      os: windows
    Lifecycle:
      Run: |
        py -3 -u {artifacts:path}/industrial_dashboard.py
```

------

**Example 例 1: マージ更新**  
次の設定更新を適用するデプロイを作成します。この更新は、マージ更新を指定しますが、リセット更新は指定しません。この設定更新は、2 基のボイラーのデータで HTTP ポート 8080 にダッシュボードを表示するように、コンポーネントに指示します。    
**マージする設定**  

```
{
  "name": "Factory 2A",
  "network": {
    "useHttps": false,
    "port": {
      "http": 8080
    }
  },
  "tags": [
    "/boiler/1/temperature",
    "/boiler/1/pressure",
    "/boiler/2/temperature",
    "/boiler/2/pressure"
  ]
}
```
次のコマンドは、コアデバイスにデプロイを作成します。  

```
aws greengrassv2 create-deployment --cli-input-json file://dashboard-deployment.json
```
`dashboard-deployment.json` ファイルには、次の JSON ドキュメントが含まれています。  

```
{
  "targetArn": "arn:aws:iot:us-west-2:123456789012:thing/MyGreengrassCore",
  "deploymentName": "Deployment for MyGreengrassCore",
  "components": {
    "com.example.IndustrialDashboard": {
      "componentVersion": "1.0.0",
      "configurationUpdate": {
        "merge": "{\"name\":\"Factory 2A\",\"network\":{\"useHttps\":false,\"port\":{\"http\":8080}},\"tags\":[\"/boiler/1/temperature\",\"/boiler/1/pressure\",\"/boiler/2/temperature\",\"/boiler/2/pressure\"]}"
      }
    }
  }
}
```
次の [Greengrass CLI](greengrass-cli-component.md) コマンドは、コアデバイスにローカルデプロイを作成します。  

```
sudo greengrass-cli deployment create \
  --recipeDir recipes \
  --artifactDir artifacts \
  --merge "com.example.IndustrialDashboard=1.0.0" \
  --update-config dashboard-configuration.json
```
`dashboard-configuration.json` ファイルには、次の JSON ドキュメントが含まれています。  

```
{
  "com.example.IndustrialDashboard": {
    "MERGE": {
      "name": "Factory 2A",
      "network": {
        "useHttps": false,
        "port": {
          "http": 8080
        }
      },
      "tags": [
        "/boiler/1/temperature",
        "/boiler/1/pressure",
        "/boiler/2/temperature",
        "/boiler/2/pressure"
      ]
    }
  }
}
```
この更新の後、ダッシュボードコンポーネントは次の設定になります:  

```
{
  "name": "Factory 2A",
  "mode": "REQUEST",
  "network": {
    "useHttps": false,
    "port": {
      "http": 8080,
      "https": 443
    }
  },
  "tags": [
    "/boiler/1/temperature",
    "/boiler/1/pressure",
    "/boiler/2/temperature",
    "/boiler/2/pressure"
  ]
}
```

**Example 例 2: 更新のリセットとマージ**  
次に、次の設定更新を適用するデプロイを作成します。この更新は、リセット更新とマージ更新を指定します。これらの更新は、デフォルトの HTTPS ポートに異なるボイラーのデータでダッシュボードを表示するように指定します。これらの更新は、前の例で示されている設定更新の結果となる設定を変更します。    
**パスのリセット**  

```
[
  "/network/useHttps",
  "/tags"
]
```  
**マージする設定**  

```
{
  "tags": [
    "/boiler/3/temperature",
    "/boiler/3/pressure",
    "/boiler/4/temperature",
    "/boiler/4/pressure"
  ]
}
```
次のコマンドは、コアデバイスにデプロイを作成します。  

```
aws greengrassv2 create-deployment --cli-input-json file://dashboard-deployment2.json
```
`dashboard-deployment2.json` ファイルには、次の JSON ドキュメントが含まれています。  

```
{
  "targetArn": "arn:aws:iot:us-west-2:123456789012:thing/MyGreengrassCore",
  "deploymentName": "Deployment for MyGreengrassCore",
  "components": {
    "com.example.IndustrialDashboard": {
      "componentVersion": "1.0.0",
      "configurationUpdate": {
        "reset": [
          "/network/useHttps",
          "/tags"
        ],
        "merge": "{\"tags\":[\"/boiler/3/temperature\",\"/boiler/3/pressure\",\"/boiler/4/temperature\",\"/boiler/4/pressure\"]}"
      }
    }
  }
}
```
次の [Greengrass CLI](greengrass-cli-component.md) コマンドは、コアデバイスにローカルデプロイを作成します。  

```
sudo greengrass-cli deployment create \
  --recipeDir recipes \
  --artifactDir artifacts \
  --merge "com.example.IndustrialDashboard=1.0.0" \
  --update-config dashboard-configuration2.json
```
`dashboard-configuration2.json` ファイルには、次の JSON ドキュメントが含まれています。  

```
{
  "com.example.IndustrialDashboard": {
    "RESET": [
      "/network/useHttps",
      "/tags"
    ],
    "MERGE": {
      "tags": [
        "/boiler/3/temperature",
        "/boiler/3/pressure",
        "/boiler/4/temperature",
        "/boiler/4/pressure"
      ]
    }
  }
}
```
この更新の後、ダッシュボードコンポーネントは次の設定になります:  

```
{
  "name": "Factory 2A",
  "mode": "REQUEST",
  "network": {
    "useHttps": true,
    "port": {
      "http": 8080,
      "https": 443
    }
  },
  "tags": [
    "/boiler/3/temperature",
    "/boiler/3/pressure",
    "/boiler/4/temperature",
    "/boiler/4/pressure",
  ]
}
```