Run automations based on EventBridge events
You can start an automation by specifying a runbook as the target of an Amazon EventBridge event. You can start automations according to a schedule, or when a specific AWS system event occurs. For example, let's say you create a runbook named BootStrapInstances that installs software on an instance when an instance starts. To specify the BootStrapInstances runbook (and corresponding automation) as a target of an EventBridge event, you first create a new EventBridge rule. (Here's an example rule: Service name: EC2, Event Type: EC2 Instance State-change Notification, Specific state(s): running, Any instance.) Then you use the following procedures to specify the BootStrapInstances runbook as the target of the event using the EventBridge console and AWS Command Line Interface (AWS CLI). When a new instance starts, the system runs the automation and installs software.
For information about creating runbooks, see Creating your own runbooks.
Creating an EventBridge event that uses a runbook (console)
Use the following procedure to configure a runbook as the target of a EventBridge event.
To configure a runbook as a target of a EventBridge event rule
Open the Amazon EventBridge console at https://console.aws.amazon.com/events/
. -
In the navigation pane, choose Rules.
-
Choose Create rule.
-
Enter a name and description for the rule.
A rule can't have the same name as another rule in the same Region and on the same event bus.
-
For Event bus, choose the event bus that you want to associate with this rule. If you want this rule to respond to matching events that come from your own AWS account, select default. When an AWS service in your account emits an event, it always goes to your account’s default event bus.
-
Choose how the rule is triggered.
To create a rule based on... Do this... Event
-
For Rule type, choose Rule with an event pattern.
-
Choose Next.
-
For Event source, choose AWS events or EventBridge partner events.
-
In the Event pattern section, do one of the following:
-
To use a template to create your event pattern, choose Event pattern form and choose Event source, AWS service, and Event type. If you choose All Events as the event type, all events emitted by the AWS service will match the rule.
To customize the template, choose Custom pattern (JSON editor) and make your changes.
-
To use a custom event pattern, choose Custom pattern (JSON editor) and create your event pattern.
-
Schedule -
For Rule type, choose Schedule.
-
Choose Next.
-
For Schedule pattern, do one of the following:
-
To use a cron expression to define the schedule, choose A fine-grained schedule that runs at a specific time, such as 8:00 a.m. PST on the first Monday of every month and enter the cron expression.
-
To use a rate expression to define the schedule, choose A schedule that runs at a regular rate, such as every 10 minutes and enter the rate expression.
-
-
-
Choose Next.
-
For Target types, choose AWS service.
-
For Select a target, choose Systems Manager Automation.
-
For Document, choose a runbook to use when your target is invoked.
-
In the Configure automation parameter(s) section, either keep the default parameter values (if available) or enter your own values.
Note
To create a target, you must specify a value for each required parameter. If you don't, the system creates the rule, but the rule won't run.
-
For many target types, EventBridge needs permissions to send events to the target. In these cases, EventBridge can create the IAM role needed for your rule to run. Do one of the following:
-
To create an IAM role automatically, choose Create a new role for this specific resource.
-
To use an IAM role that you created earlier, choose Use existing role and select the existing role from the dropdown. Note that you might need to update the trust policy for your IAM role to include EventBridge. The following is an example:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "Service": [ "
events.amazonaws.com
", "ssm.amazonaws.com" ] }, "Action": "sts:AssumeRole" } ] } -
-
Choose Next.
-
(Optional) Enter one or more tags for the rule. For more information, see Tagging Your Amazon EventBridge Resources in the Amazon EventBridge User Guide.
-
Choose Next.
-
Review the details of the rule and choose Create rule.
Create an EventBridge event that uses a runbook (command line)
The following procedure describes how to use the AWS CLI (on Linux or Windows) or AWS Tools for PowerShell to create an EventBridge event rule and configure a runbook as the target.
To configure a runbook as a target of an EventBridge event rule
Install and configure the AWS CLI or the AWS Tools for PowerShell, if you haven't already.
For information, see Installing or updating the latest version of the AWS CLI and Installing the AWS Tools for PowerShell.
-
Create a command to specify a new EventBridge event rule. Replace each
example resource placeholder
with your own information.Triggers based on a schedule
The following example creates an EventBridge event rule that starts every day at 9:00 AM (UTC).
Triggers based on an event
The following example creates an EventBridge event rule that starts when any EC2 instance in the Region changes state.
The command returns details for the new EventBridge rule similar to the following.
-
Create a command to specify a runbook as a target of the EventBridge event rule you created in step 2. Replace each
example resource placeholder
with your own information.The following example creates an EventBridge event target that starts the specified instance ID using the runbook
AWS-StartEC2Instance
.The system returns information like the following.