Walkthrough: Using input transformers with Automation - AWS Systems Manager

Walkthrough: Using input transformers with Automation

This AWS Systems Manager Automation walkthrough shows how to use the input transformer feature of Amazon EventBridge to extract the instance-id of an Amazon Elastic Compute Cloud (Amazon EC2) instance from an instance state change event. Automation is a capability of AWS Systems Manager. We use the input transformer to pass that data to the AWS-CreateImage runbook target as the InstanceId input parameter. The rule is triggered when any instance changes to the stopped state.

For more information about working with input transformers, see Tutorial: Use Input Transformer to Customize What is Passed to the Event Target in the Amazon EventBridge User Guide.

Before you begin

Verify that you added the required permissions and trust policy for EventBridge to your Systems Manager Automation service role. For more information, see Overview of Managing Access Permissions to Your EventBridge Resources in the Amazon EventBridge User Guide.

To use input transformers with Automation

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

  2. In the navigation pane, choose Rules, and then choose Create rule.

    -or-

    If the Amazon EventBridge home page opens first, choose Create rule.

  3. 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.

  4. For Define pattern, do the following:

    1. Choose Event pattern.

    2. For Event matching pattern, choose Pre-defined pattern by service.

    3. For Event matching pattern, choose Pre-defined pattern by service.

    4. For Service provider, choose AWS.

    5. For Service name, choose EC2.

    6. For Event type, choose EC2 Instance State-change Notification.

    7. Choose Specific state(s) and stopped from the dropdown.

    8. Choose Any instance.

  5. For Select event bus, choose the event bus that you want to associate with this rule. If you want this rule to trigger on matching events that come from your own AWS account, select AWS default event bus. When an AWS service in your account emits an event, it always goes to your account’s default event bus.

  6. For Target, choose Systems Manager Automation.

  7. For Document, choose AWS-CreateImage.

  8. Expand Configure automation parameter(s) and choose Input Transformer.

  9. In the first box under Input Transformer, enter {"instance":"$.detail.instance-id"}.

  10. In the second box, enter {"InstanceId":[<instance>]}.

  11. Choose Use existing role and choose your Automation service role.

  12. (Optional) Enter one or more tags for the rule. For more information, see Tagging Your Amazon EventBridge Resources in the Amazon EventBridge User Guide.

  13. Choose Create.