Skip to main content

Event-based Automation: Tag control on a new EC2 instance

In this tutorial we will show you how to create an Automation that controls tags applied when a new EC2 instance is created. This enables a simple way to manage and use best practices, as the Automation checks the tags as soon as the instance is created on your account. The Automation determines whether one or less tags are applied to the instance, and if so it will notify a predefined channel or user on Slack.

Prerequisites

Overview

This is an overview of the procedure of creating the manual Automation.

Before we begin:

  1. Creating a new Pack.
  2. Creating a new Automation.

Creating Automations Steps:

  1. Using an if Step to check if there is one or less tags assigned to the new EC2 instance.
  2. Asking permission via Slack.

Testing the Automation.

Before we begin

Creating a new Pack

A Pack is a collection of Automations. If you already have a Pack you can open it and skip ahead to creating a new Automation.
If you don't have an existing pack, follow these steps:

  1. On your Automation screen, click Create new Pack.
  2. Enter
    Pack name: My first Pack
  3. Click Create. The new Pack is displayed on your Automations screen.

Creating a new Automation

  1. Click Create Automation.
  2. Enter the parameters: Automation name: Tag control on a new EC2 instanceDescription: This Automation will be triggered when a new EC2 instances is created and will check the tags.
  3. Select a type of trigger: Event-based Automation .
  4. Select AWS > AWS EC2 new instances > Continue.
  5. In Trigger setup select or create an AWS connection (awsconnection).
  6. Enter Region: eu-west-1.
  7. Click Apply > Create Automation. You are redirected to the Edit page of the Automation.

triggerSetupExternalEvent

Creating the Automation Steps

Proceed to create the Steps of your Automation as described in the following section.

Step 1: Using an if Step to check if there is one or less tags assigned to the new EC2 instance

  1. Click to open the Action panel. Alternatively, you can drag Actions to your flow, from the menu on the left side of your Edit screen.
  2. Select if Step by clicking if.
  3. Click on Action #1 to change the name of the action to Checking number of tags.
  4. Enter the condition using expression language into the condition editor. {{len(event_payload.tags)}} Less or equals to equals 1 If one tag or less is found, Step 2 occurs. If more than one tag is found, Automation stops.

Step 2: Asking permission via Slack

  1. Click to open the Action panel. Alternatively, you can drag Actions to your flow, from the menu on the left side of your Edit screen.

  2. Search and select the Slack > Send message to channel Action.

  3. For the Step to work, a connection to Slack is required. On the right-hand corner of your Step, select Select Connection > slack_connection. If you do not have a Slack connection, click Create new connection.

  4. Enter the following parameters in your Step.

    • Click on Action #7 to change the name of the action to Notify via Slack.
    ParameterDescriptionExample
    ChannelReceipts channel name.Random
    TextDescriptive text.The following instance {{event_payload.instance}} in{{event_payload.placement}} violates tagging policy. Here are the attached tags. {{len(event_payload.tags)}}

Testing the Automation

You can test your Automation before you publish it. An event-based Automations can be tested using a JSON sample of a potential incoming event. To run a test, use the following instructions:

  1. From the Edit mode, save your draft and do a Test run of your Automation.
  2. Click Test run. A sample event is displayed in the Event sample text area and the sample can be edited.
  3. You can change the runner to run the Automation with a runner that is not the default. The default runner is Blink Cloud.
  4. Click Apply.
  5. Click Run test.
  6. When your Automation is successful, you can Publish it. This will over ride any previous versions created and published.

EventBasedSample