

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

# EventBridge イベントに基づくオートメーションを実行する
<a name="running-automations-event-bridge"></a>

ランブックを Amazon EventBridge イベントのターゲットとして指定することで、オートメーションを開始できます。オートメーションは、スケジュールに従って、または特定の AWS システムイベントが発生したときに開始できます。たとえば、インスタンスの起動時にインスタンスにソフトウェアをインストールする *BootStrapInstances* というランブックを作成するとします。*BootStrapInstances* ランブック (および対応するオートメーション) を EventBridge イベントのターゲットとして指定するには、まず新しい EventBridge ルールを作成します。(ルール例は次のとおりです: **Service name**: EC2、**Event Type**: EC2 Instance State-change Notification、**Specific state(s)**: running、**Any instance**。) 次に、以下の手順により、EventBridge コンソールおよび AWS Command Line Interface (AWS CLI) を使用し、*BootStrapInstances* ランブックをイベントのターゲットに指定します。新しいインスタンスが起動すると、システムによってオートメーションが実行されソフトウェアがインストールされます。

ランブックの作成の詳細については、「[独自のランブックの作成](automation-documents.md)」を参照してください。

## ランブックを使用する EventBridge イベントを作成する (コンソール)
<a name="automation-cwe-target-console"></a>

ランブックを EventBridge イベントのターゲットとして設定するには、以下の手順を使用します。

**EventBridge イベントルールのターゲットとしてランブックを設定するには**

1. Amazon EventBridge コンソール ([https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/)) を開きます。

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

1. **[ルールの作成]** を選択します。

1. ルールの名前と説明を入力します。

   ルールには同じリージョン内および同じイベントバス上の別のルールと同じ名前を付けることはできません。

1. **[イベントバス]** で、このルールに関連付けるイベントバスを選択します。このルールを使用して、自分の AWS アカウント の一致するイベントに応答する場合は、[**default**] ( デフォルト) を選択します。アカウントの AWS のサービスで発生したイベントは、常にアカウントのデフォルトのイベントバスに移動します。

1. ルールをトリガーする方法を選択します。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/running-automations-event-bridge.html)

1. [**次へ**] を選択します。

1. **[ターゲットタイプ]** では、**[AWS サービス]** を選択します。

1. [**Select a target**] (ターゲットを選択) では、[**Systems Manager オートメーション**] を選択します。

1. [**Document (ドキュメント)**] で、ターゲットが呼び出されたときに使用するランブックを選択します。

1. [**Configure automation parameter(s)**] (自動化パラメータの設定) を展開して、デフォルトのパラメータ値 (使用可能な場合) のままにするか、独自の値を入力します。
**注記**  
ターゲットを作成するには、各必須パラメータの値を指定する必要があります。指定しない場合、ルールは作成されますが、実行はされません。

1. 多くのターゲットタイプでは、EventBridge はターゲットにイベントを送信するためのアクセス許可が必要です。これらの場合、EventBridge は、イベントの実行に必要な IAM ロールを作成できます。次のいずれかを行います。
   + 自動的に IAM ロールを作成するには、**この特定のリソースに対して新しいロールを作成する** を選択します。
   + 以前に作成した IAM ロールを使用するには、**[Use existing role]** (既存のロールの使用) を選択し、ドロップダウンから既存のロールを選択します。EventBridge を含むように IAM ロールの信頼ポリシーを更新する必要がある場合があります。以下に例を示します。

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "",
               "Effect": "Allow",
               "Principal": {
                   "Service": [
                       "events.amazonaws.com",
                       "ssm.amazonaws.com"
                   ]
               },
               "Action": "sts:AssumeRole"
           }
       ]
   }
   ```

------

1. [**次へ**] を選択します。

1. (オプション) ルールに 1 つ以上のタグを入力します。詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge リソースのタグ付け](https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-tagging.html)」を参照してください 。

1. [**次へ**] を選択します。

1. ルールの詳細を確認し、**ルールの作成** を選択します。

## ランブックを使用する EventBridge イベントの作成 (コマンドライン)
<a name="automation-cwe-target-commandline"></a>

次の手順では、AWS CLI (Linux または Windows の場合) または AWS Tools for PowerShell を使用して、EventBridge イベントルールを作成し、ランブックをターゲットとして設定する方法を説明します。

**ランブックを EventBridge イベントルールのターゲットとして設定するには**

1. まだ AWS CLI または AWS Tools for PowerShell をインストールして設定していない場合は、インストールして設定します。

   詳細については、「[AWS CLI の最新バージョンをインストールまたは更新します。](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)」および「[AWS Tools for PowerShell のインストール](https://docs.aws.amazon.com/powershell/latest/userguide/pstools-getting-set-up.html)」を参照してください。

1. 新しい EventBridge イベントルールを指定するコマンドを作成します。各*リソースプレースホルダーの例*をユーザー自身の情報に置き換えます。

   *スケジュールに基づいてトリガー*

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

   ```
   aws events put-rule \
   --name "rule name" \
   --schedule-expression "cron or rate expression"
   ```

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

   ```
   aws events put-rule ^
   --name "rule name" ^
   --schedule-expression "cron or rate expression"
   ```

------
#### [ PowerShell ]

   ```
   Write-CWERule `
   -Name "rule name" `
   -ScheduleExpression "cron or rate expression"
   ```

------

   次の例では、毎日午前 9:00 (UTC) に開始される EventBridge イベントルールを作成します。

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

   ```
   aws events put-rule \
   --name "DailyAutomationRule" \
   --schedule-expression "cron(0 9 * * ? *)"
   ```

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

   ```
   aws events put-rule ^
   --name "DailyAutomationRule" ^
   --schedule-expression "cron(0 9 * * ? *)"
   ```

------
#### [ PowerShell ]

   ```
   Write-CWERule `
   -Name "DailyAutomationRule" `
   -ScheduleExpression "cron(0 9 * * ? *)"
   ```

------

   *イベントに基づいてトリガー*

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

   ```
   aws events put-rule \
   --name "rule name" \
   --event-pattern "{\"source\":[\"aws.service\"],\"detail-type\":[\"service event detail type\"]}"
   ```

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

   ```
   aws events put-rule ^
   --name "rule name" ^
   --event-pattern "{\"source\":[\"aws.service\"],\"detail-type\":[\"service event detail type\"]}"
   ```

------
#### [ PowerShell ]

   ```
   Write-CWERule `
   -Name "rule name" `
   -EventPattern '{"source":["aws.service"],"detail-type":["service event detail type"]}'
   ```

------

   次の例では、リージョン内の任意の EC2 インスタンスの状態が変更されたときに開始される EventBridge イベントルールを作成します。

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

   ```
   aws events put-rule \
   --name "EC2InstanceStateChanges" \
   --event-pattern "{\"source\":[\"aws.ec2\"],\"detail-type\":[\"EC2 Instance State-change Notification\"]}"
   ```

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

   ```
   aws events put-rule ^
   --name "EC2InstanceStateChanges" ^
   --event-pattern "{\"source\":[\"aws.ec2\"],\"detail-type\":[\"EC2 Instance State-change Notification\"]}"
   ```

------
#### [ PowerShell ]

   ```
   Write-CWERule `
   -Name "EC2InstanceStateChanges" `
   -EventPattern '{"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"]}'
   ```

------

   このコマンドでは、次のような新しい EventBridge ルールの詳細が返されます。

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

   ```
   {
   "RuleArn": "arn:aws:events:us-east-1:123456789012:rule/automationrule"
   }
   ```

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

   ```
   {
   "RuleArn": "arn:aws:events:us-east-1:123456789012:rule/automationrule"
   }
   ```

------
#### [ PowerShell ]

   ```
   arn:aws:events:us-east-1:123456789012:rule/EC2InstanceStateChanges
   ```

------

1. ステップ 2 で作成した EventBridge イベントルールのターゲットとして、ランブックを指定するコマンドを作成します。各*リソースプレースホルダーの例*をユーザー自身の情報に置き換えます。

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

   ```
   aws events put-targets \
   --rule rule name \
   --targets '{"Arn": " arn:aws:ssm:region:account ID:automation-definition/runbook name","Input":"{\"Message\":[\"{\\\"Key\\\":\\\"key name\\\",\\\"Values\\\":[\\\"value\\\"]}\"]}","Id": "target ID","RoleArn": "arn:aws:iam::123456789012:role/service-role/EventBridge service role"}'
   ```

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

   ```
   aws events put-targets ^
   --rule rule name ^
   --targets '{"Arn": "arn:aws:ssm:region:account ID:automation-definition/runbook name","Input":"{\"Message\":[\"{\\\"Key\\\":\\\"key name\\\",\\\"Values\\\":[\\\"value\\\"]}\"]}","Id": "target ID","RoleArn": "arn:aws:iam::123456789012:role/service-role/EventBridge service role"}'
   ```

------
#### [ PowerShell ]

   ```
   $Target = New-Object Amazon.CloudWatchEvents.Model.Target
   $Target.Id = "target ID"
   $Target.Arn = "arn:aws:ssm:region:account ID:automation-definition/runbook name"
   $Target.RoleArn = "arn:aws:iam::123456789012:role/service-role/EventBridge service role"
   $Target.Input = '{"input parameter":["value"],"AutomationAssumeRole":["arn:aws:iam::123456789012:role/AutomationServiceRole"]}'
   
   Write-CWETarget `
   -Rule "rule name" `
   -Target $Target
   ```

------

   次の例では、ランブック `AWS-StartEC2Instance` を使用して指定されたインスタンス ID を起動する EventBridge イベントターゲットを作成します。

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

   ```
   aws events put-targets \
   --rule DailyAutomationRule \
   --targets '{"Arn": "arn:aws:ssm:region:*:automation-definition/AWS-StartEC2Instance","Input":"{\"InstanceId\":[\"i-02573cafcfEXAMPLE\"],\"AutomationAssumeRole\":[\"arn:aws:iam::123456789012:role/AutomationServiceRole\"]}","Id": "Target1","RoleArn": "arn:aws:iam::123456789012:role/service-role/AWS_Events_Invoke_Start_Automation_Execution_1213609520"}'
   ```

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

   ```
   aws events put-targets ^
   --rule DailyAutomationRule ^
   --targets '{"Arn": "arn:aws:ssm:region:*:automation-definition/AWS-StartEC2Instance","Input":"{\"InstanceId\":[\"i-02573cafcfEXAMPLE\"],\"AutomationAssumeRole\":[\"arn:aws:iam::123456789012:role/AutomationServiceRole\"]}","Id": "Target1","RoleArn": "arn:aws:iam::123456789012:role/service-role/AWS_Events_Invoke_Start_Automation_Execution_1213609520"}'
   ```

------
#### [ PowerShell ]

   ```
   $Target = New-Object Amazon.CloudWatchEvents.Model.Target
   $Target.Id = "Target1"
   $Target.Arn = "arn:aws:ssm:region:*:automation-definition/AWS-StartEC2Instance"
   $Target.RoleArn = "arn:aws:iam::123456789012:role/service-role/AWS_Events_Invoke_Start_Automation_Execution_1213609520"
   $Target.Input = '{"InstanceId":["i-02573cafcfEXAMPLE"],"AutomationAssumeRole":["arn:aws:iam::123456789012:role/AutomationServiceRole"]}'
   
   Write-CWETarget `
   -Rule "DailyAutomationRule" `
   -Target $Target
   ```

------

   システムが以下のような情報を返します。

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

   ```
   {
   "FailedEntries": [],
   "FailedEntryCount": 0
   }
   ```

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

   ```
   {
   "FailedEntries": [],
   "FailedEntryCount": 0
   }
   ```

------
#### [ PowerShell ]

   PowerShell のコマンドが成功した場合、出力はありません。

------