Amazon EventBridge
User Guide

Tutorial: Use EventBridge to Relay Events to AWS Systems Manager Run Command

You can use Amazon EventBridge to invoke AWS Systems Manager Run Command and perform actions on Amazon EC2 instances when certain events happen. In this tutorial, set up Systems Manager Run Command to run shell commands and configure each new instance that is launched in an Amazon EC2 Auto Scaling group. This tutorial assumes that you have already assigned a tag to the Amazon EC2 Auto Scaling group, with environment as the key and production as the value.

To create the EventBridge rule

  1. Open the Amazon EventBridge console at https://console.aws.amazon.com/events/.

  2. In the navigation pane, choose Rules.

  3. Choose Create rule.

  4. Enter a name and description for the rule.

  5. For Define pattern, do the following:

    1. Choose Event pattern.

    2. Choose Pre-defined pattern by service.

    3. For Service provider, choose AWS.

    4. For Service Name, choose Auto Scaling.

    5. For Event type, choose Instance Launch and Terminate.

    6. Choose Specific instance event(s), EC2 Instance-launch Lifecycle Action.

    7. By default, the rule matches any Amazon EC2 Auto Scaling group in the Region. To make the rule match a specific group, choose Specific group name(s) and select one or more groups.

  6. For Select event bus, choose AWS default event bus. When an AWS service in your account emits an event, it always goes to your account’s default event bus.

  7. For Target, select SSM Run Command .

  8. For Document, choose AWS-RunShellScript.

    For Target key, type tag:environment. For Target value(s), enter production and choose Add.

  9. Under Configure automation parameter(s), do the following:

    1. Choose Constant.

    2. For Commands, enter a shell command and choose Add. Repeat this step for all commands to run when an instance launches.

    3. If necessary, enter the appropriate information in WorkingDirectory and ExecutionTimeout.

  10. EventBridge can create the IAM role needed for your event to run:

    • To create an IAM role automatically, choose Create a new role for this specific resource

    • To use an IAM role that you created before, choose Use existing role

  11. Choose Create rule.