

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

# PCS AWS のノードライフサイクルアクションの例
<a name="cng-node-lifecycle-actions-examples"></a>

次の例では AWS CLI 、 を使用してノードライフサイクルアクションを設定します。を使用してコンピューティングノードグループを作成するとき`create-compute-node-group`、または を使用して既存のコンピューティングノードグループに追加または変更するときに、ライフサイクルアクションを定義できます`update-compute-node-group`。`--node-lifecycle-actions` 値は両方のコマンドで同じです。

## ステージ間で複数のスクリプト
<a name="cng-node-lifecycle-actions-examples-multiple"></a>

この例では、異なる実行ポリシーとエラー動作を使用して、両方のライフサイクルステージにわたってスクリプトを組み合わせます。

```
aws pcs create-compute-node-group --region {{region}} \
  --cluster-identifier {{my-cluster}} \
  --compute-node-group-identifier {{my-cng}} \
  --subnet-ids {{subnet-ExampleID1}} \
  --custom-launch-template id={{lt-ExampleID1}},version='{{1}}' \
  --iam-instance-profile-arn={{arn:InstanceProfile}} \
  --scaling-config minInstanceCount={{0}},maxInstanceCount={{10}} \
  --instance-configs instanceType={{t3.large}} \
  --node-lifecycle-actions '{
    "stages": {
      "nodeBootstrapped": [
        { "name": "Mount FSx Lustre", "scriptSource": { "scriptLocation": "s3://{{my-bucket}}/mount-fsx.sh" }, "arguments": ["fs-{{0abc123}}", "/scratch"], "executionPolicy": "EVERY_BOOT" },
        { "name": "Join Active Directory", "scriptSource": { "scriptLocation": "s3://{{my-bucket}}/configure-ad.sh" }, "arguments": ["ad.example.com", "EXAMPLE"], "executionPolicy": "FIRST_BOOT_ONLY" }
      ],
      "nodeReady": [
        { "name": "Configure CloudWatch logging", "scriptSource": { "scriptLocation": "s3://{{my-bucket}}/setup-cloudwatch.sh" }, "arguments": ["/aws/pcs/{{my-cluster}}"], "onError": "CONTINUE" }
      ]
    }
  }'
```

## 混合エラー動作
<a name="cng-node-lifecycle-actions-examples-mixed-error"></a>

この例では、同じステージで重要なスクリプトとオプションのスクリプトを使用します。1 つ目は障害発生時にノードを終了し、2 つ目は続行します。

```
aws pcs create-compute-node-group --region {{region}} \
  --cluster-identifier {{my-cluster}} \
  --compute-node-group-identifier {{my-cng}} \
  --subnet-ids {{subnet-ExampleID1}} \
  --custom-launch-template id={{lt-ExampleID1}},version='{{1}}' \
  --iam-instance-profile-arn={{arn:InstanceProfile}} \
  --scaling-config minInstanceCount={{0}},maxInstanceCount={{10}} \
  --instance-configs instanceType={{t3.large}} \
  --node-lifecycle-actions '{
    "stages": {
      "nodeBootstrapped": [
        { "name": "Install required packages", "scriptSource": { "scriptLocation": "s3://{{my-bucket}}/install-packages.sh" }, "onError": "TERMINATE" },
        { "name": "Install optional tools", "scriptSource": { "scriptLocation": "s3://{{my-bucket}}/install-optional.sh" }, "onError": "CONTINUE" }
      ]
    }
  }'
```

## チェックサムを使用した整合性の検証
<a name="cng-node-lifecycle-actions-examples-checksum"></a>

SHA-256 チェックサムを追加して、コンテンツが一致しない場合にエージェントがスクリプトを拒否するようにします。

```
aws pcs update-compute-node-group \
  --cluster-identifier {{my-cluster}} \
  --compute-node-group-identifier {{my-cng}} \
  --node-lifecycle-actions '{
    "stages": {
      "nodeBootstrapped": [
        {
          "name": "Mount EFS",
          "scriptSource": {
            "scriptLocation": "s3://{{my-bucket}}/mount-efs.sh",
            "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
          },
          "arguments": ["fs-{{12345678}}", "/shared"]
        }
      ]
    }
  }'
```

## 再起動時にスクリプトの更新を有効にする
<a name="cng-node-lifecycle-actions-examples-refresh"></a>

を `scriptCachingPolicy`に設定します`REFRESH_ON_REBOOT`。この`UpdateComputeNodeGroup`呼び出しは設定変更であるため、既存のインスタンスをドレインして置き換えます。置き換えが完了すると、インスタンスは再起動のたびにスクリプトを再ダウンロードします。その後、Amazon S3 のスクリプトコンテンツを更新できます。インスタンスは、以降の API コールなしで次の再起動時に変更を取得します。

```
aws pcs update-compute-node-group \
  --cluster-identifier {{my-cluster}} \
  --compute-node-group-identifier {{my-cng}} \
  --node-lifecycle-actions '{
    "stages": { "nodeBootstrapped": [ { "name": "Mount EFS", "scriptSource": { "scriptLocation": "s3://{{my-bucket}}/mount-efs.sh" }, "arguments": ["fs-{{12345678}}", "/shared"], "executionPolicy": "EVERY_BOOT" } ] },
    "scriptCachingPolicy": "REFRESH_ON_REBOOT"
  }'
```

## AWS ParallelCluster ブートストラップアクションからの移行
<a name="cng-node-lifecycle-actions-examples-migrate"></a>

多くの既存の AWS ParallelCluster ブートストラップスクリプトは、PCS AWS ライフサイクルアクションでそのまま動作します。 AWS PCS は、スクリプトごとのエラー処理 (`TERMINATE`、`STOP_SEQUENCE`、または `CONTINUE`) と再起動制御 (`FIRST_BOOT_ONLY` または ) を提供します`EVERY_BOOT`。PCS AWS のデフォルトは です`FIRST_BOOT_ONLY`。ParallelCluster の動作 (起動ごとに実行) を一致させるには、 `executionPolicy` を に設定します`EVERY_BOOT`。


| **AWS ParallelCluster** | **AWS PCS** | 
| --- | --- | 
| `OnNodeStart` | `nodeBootstrapped` (PCS AWS 設定フェーズの後、 より前に実行されます`slurmd`) | 
| `OnNodeConfigured` | `nodeReady` (ノードが Slurm コントローラーに登録された後に実行されます) | 
| `OnNodeUpdated` | 同等の PCS AWS がない | 