

• AWS Systems Manager CloudWatch ダッシュボードは、2026 年 4 月 30 日以降は利用できなくなります。お客様は、これまでと同様に Amazon CloudWatch コンソールを使用して、Amazon CloudWatch ダッシュボードの表示、作成、管理を継続できます。詳細については、「[Amazon CloudWatch ダッシュボードのドキュメント](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)」を参照してください。

# Run Command コマンドを使用した Parameter Store でのパラメータの操作
<a name="sysman-param-runcommand"></a>

AWS Systems Manager のツールである Run Command でパラメータを使用できます。詳細については、「[AWS Systems Manager Run Command](run-command.md)」を参照してください。

## コンソールを使用して String パラメータを実行する
<a name="param-test-console"></a>

次の手順では、`String` パラメータを使用するコマンドを実行するプロセスを順を追って説明します。

**Parameter Store を使用して文字列パラメータを実行するには**

1. AWS Systems Manager コンソール ([https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/)) を開きます。

1. ナビゲーションペインで、**[Run Command]** を選択します。

1. [**Run command (コマンドの実行)**] を選択します。

1. [**コマンドのドキュメント**] リストで、[`AWS-RunPowerShellScript`] (Windows) または [`AWS-RunShellScript`] (Linux) を選択します。

1. [**コマンドパラメータ**] で、**echo \$1\$1ssm:*parameter-name*\$1\$1** と入力します。例: **echo \$1\$1ssm:/Test/helloWorld\$1\$1**。

1. **[Targets]** (ターゲット) セクションで、タグの指定、インスタンスやエッジデバイスの手動選択、リソースグループの指定により、このオペレーションを実行するマネージドノードを選択します。
**ヒント**  
表示されるはずのマネージドノードが表示されない場合は、トラブルシューティングのヒントについて「[マネージドノードの可用性のトラブルシューティング](fleet-manager-troubleshooting-managed-nodes.md)」を参照してください。

1. **[その他のパラメータ]** で、以下の操作を行います。
   + **[コメント]** に、このコマンドに関する情報を入力します。
   + **[タイムアウト (秒)]** に、コマンドの実行全体が失敗するまでにシステムが待機する秒数を指定します。

1. **[レート制御]** の場合:
   + **[同時実行数]** の場合、コマンドを同時に実行するマネージドノードの数または割合を指定します。
**注記**  
マネージドノードに適用されるタグを指定するか、AWS リソースグループを指定してターゲットを選択し、ターゲットとなるマネージドノードの数が不明な場合は、割合を指定してドキュメントを同時に実行できるターゲットの数を制限します。
   + **[エラーのしきい値]** で、ノードの数または割合のいずれかで失敗した後、他のマネージドノードでのコマンドの実行をいつ停止するか指定します。例えば、3 つのエラーを指定した場合、4 番目のエラーが受信されると、システムマネージャー はコマンドの送信を停止します。コマンドを処理しているマネージドノードもエラーを送信する可能性があります。

1. (オプション) コマンド出力をファイルに保存する場合は、**[出力オプション]** の **[S3 バケットにコマンド出力を書き込む]** ボックスを選択します。ボックスにバケット名とプレフィックス (フォルダ) 名を入力します。
**注記**  
S3 バケットにデータを書き込む機能を許可する S3 許可は、このタスクを実行する IAM ユーザーのものではなく、インスタンスに割り当てられたインスタンスプロファイル (EC2 インスタンスの場合) または IAM サービスロール (ハイブリッドアクティベーションマシン) のものです。詳細については、「[Systems Manager に必要なインスタンスのアクセス許可を設定する](setup-instance-permissions.md)」または「[ハイブリッド環境に IAM サービスロールを作成する](hybrid-multicloud-service-role.md)」を参照してください。さらに、指定された S3 バケットが別の AWS アカウント にある場合は、マネージドノードに関連付けられたインスタンスプロファイルまたは IAM サービスロールが、そのバケットへの書き込みに必要なアクセス許可があることを確認してください。

1. [**SNS Notifications (SNS 通知)**] セクションで、コマンドの実行状態に関する通知を受け取る場合は、[**Enable SNS notifications (SNS 通知を有効にする)**] チェックボックスをオンにします。

   Run Command 用の Amazon SNS 通知の設定の詳細については、「[Amazon SNS 通知を使用した Systems Manager のステータス変更のモニタリング](monitoring-sns-notifications.md)」を参照してください。

1. [**Run** (実行)] を選択します。

1. [**Command ID**] (コマンド ID) ページの [**Targets and outputs**] (ターゲットと出力) エリアで、コマンドを実行したノードの ID の横にあるボタンを選択し、[**View output**] (出力の表示) を選択します。コマンドの出力が、パラメータに指定した値 (**This is my first parameter** など) であることを確認します。

## AWS CLI を使用してパラメータを実行する
<a name="param-test-cli"></a>

**例 1: シンプルコマンド**  
次のコマンドの例には、`DNS-IP` という名前の Systems Manager パラメータが含まれています。このパラメータの値は単純なノードの IP アドレスです。この例では、AWS Command Line Interface (AWS CLI) コマンドを使用してパラメータ値をエコーします。

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name "AWS-RunShellScript" \
    --document-version "1" \
    --targets "Key=instanceids,Values=i-02573cafcfEXAMPLE" \
    --parameters "commands='echo {{ssm:DNS-IP}}'" \
    --timeout-seconds 600 \
    --max-concurrency "50" \
    --max-errors "0" \
    --region us-east-2
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name "AWS-RunPowerShellScript" ^
    --document-version "1" ^
    --targets "Key=instanceids,Values=i-02573cafcfEXAMPLE" ^
    --parameters "commands='echo {{ssm:DNS-IP}}'" ^
    --timeout-seconds 600 ^
    --max-concurrency "50" ^
    --max-errors "0" ^
    --region us-east-2
```

------

このコマンドによって以下のような情報が返されます。

```
{
    "Command": {
        "CommandId": "c70a4671-8098-42da-b885-89716EXAMPLE",
        "DocumentName": "AWS-RunShellScript",
        "DocumentVersion": "1",
        "Comment": "",
        "ExpiresAfter": "2023-12-26T15:19:17.771000-05:00",
        "Parameters": {
            "commands": [
                "echo {{ssm:DNS-IP}}"
            ]
        },
        "InstanceIds": [],
        "Targets": [
            {
                "Key": "instanceids",
                "Values": [
                    "i-02573cafcfEXAMPLE"
                ]
            }
        ],
        "RequestedDateTime": "2023-12-26T14:09:17.771000-05:00",
        "Status": "Pending",
        "StatusDetails": "Pending",
        "OutputS3Region": "us-east-2",
        "OutputS3BucketName": "",
        "OutputS3KeyPrefix": "",
        "MaxConcurrency": "50",
        "MaxErrors": "0",
        "TargetCount": 0,
        "CompletedCount": 0,
        "ErrorCount": 0,
        "DeliveryTimedOutCount": 0,
        "ServiceRole": "",
        "NotificationConfig": {
            "NotificationArn": "",
            "NotificationEvents": [],
            "NotificationType": ""
        },
        "CloudWatchOutputConfig": {
            "CloudWatchLogGroupName": "",
            "CloudWatchOutputEnabled": false
        },
        "TimeoutSeconds": 600,
        "AlarmConfiguration": {
            "IgnorePollAlarmFailure": false,
            "Alarms": []
        },
        "TriggeredAlarms": []
    }
}
```

コマンドの実行が完了したら、以下のコマンドを使ってそのコマンドに関する詳細情報を表示できます。
+ [https://docs.aws.amazon.com/cli/latest/reference/ssm/get-command-invocation.html](https://docs.aws.amazon.com/cli/latest/reference/ssm/get-command-invocation.html) — コマンドの実行に関する詳細情報を表示します。
+ [https://docs.aws.amazon.com/cli/latest/reference/ssm/link-cli-ref-list-command-invocations.html](https://docs.aws.amazon.com/cli/latest/reference/ssm/link-cli-ref-list-command-invocations.html) — 特定のマネージドノードにおけるコマンドの実行ステータスを表示します。
+ [https://docs.aws.amazon.com/cli/latest/reference/ssm/link-cli-ref-list-commands.html](https://docs.aws.amazon.com/cli/latest/reference/ssm/link-cli-ref-list-commands.html) — 複数のマネージドノードにおけるコマンドの実行ステータスを表示します。

**例 2: `SecureString` パラメータ値を復号する**  
次のコマンド例では、**SecurePassword** という名前の `SecureString` パラメータを使用します。`parameters` フィールドで使用されるコマンドは、`SecureString` パラメータの値を取得および復号化した後、クリアテキストでパスワードを渡すことなくローカル管理者パスワードをリセットします。

------
#### [ Linux ]

```
aws ssm send-command \
        --document-name "AWS-RunShellScript" \
        --document-version "1" \
        --targets "Key=instanceids,Values=i-02573cafcfEXAMPLE" \
        --parameters '{"commands":["secure=$(aws ssm get-parameters --names SecurePassword --with-decryption --query Parameters[0].Value --output text --region us-east-2)","echo $secure | passwd myuser --stdin"]}' \
        --timeout-seconds 600 \
        --max-concurrency "50" \
        --max-errors "0" \
        --region us-east-2
```

------
#### [ Windows ]

```
aws ssm send-command ^
        --document-name "AWS-RunPowerShellScript" ^
        --document-version "1" ^
        --targets "Key=instanceids,Values=i-02573cafcfEXAMPLE" ^
        --parameters "commands=['$secure = (Get-SSMParameterValue -Names SecurePassword -WithDecryption $True).Parameters[0].Value','net user administrator $secure']" ^
        --timeout-seconds 600 ^
        --max-concurrency "50" ^
        --max-errors "0" ^
        --region us-east-2
```

------

**例 3: SSM ドキュメント内のパラメータを参照する**  
また、以下の例に示すように、SSM ドキュメントの *Parameters* セクションで Systems Manager パラメータを参照することもできます。

```
{
   "schemaVersion":"2.0",
   "description":"Sample version 2.0 document v2",
   "parameters":{
      "commands" : {
        "type": "StringList",
        "default": ["{{ssm:parameter-name}}"]
      }
    },
    "mainSteps":[
       {
          "action":"aws:runShellScript",
          "name":"runShellScript",
          "inputs":{
             "runCommand": "{{commands}}"
          }
       }
    ]
}
```

SSM ドキュメントの `runtimeConfig` セクションで使用されている *ローカルパラメータ*と同様の構文を、Parameter Store パラメータと混同しないでください。ローカルパラメータは、Systems Manager のパラメータと同じではありません。「`ssm:`」というプレフィックスを付けないことで、ローカルパラメータを Systems Manager パラメータから区別できます。

```
"runtimeConfig":{
        "aws:runShellScript":{
            "properties":[
                {
                    "id":"0.aws:runShellScript",
                    "runCommand":"{{ commands }}",
                    "workingDirectory":"{{ workingDirectory }}",
                    "timeoutSeconds":"{{ executionTimeout }}"
```

**注記**  
SSM ドキュメントは、`SecureString` パラメータへのリファレンスをサポートしていません。たとえば、Run Command で `SecureString` パラメータを使用するには、以下の例に示すように、Run Command に渡す前にパラメータ値を取得する必要があります。  

```
value=$(aws ssm get-parameters --names parameter-name --with-decryption)
```

```
aws ssm send-command \
    --name AWS-JoinDomain \
    --parameters password=$value \
    --instance-id instance-id
```

```
aws ssm send-command ^
    --name AWS-JoinDomain ^
    --parameters password=$value ^
    --instance-id instance-id
```

```
$secure = (Get-SSMParameterValue -Names parameter-name -WithDecryption $True).Parameters[0].Value | ConvertTo-SecureString -AsPlainText -Force
```

```
$cred = New-Object System.Management.Automation.PSCredential -argumentlist user-name,$secure
```