Using Input Transformer while using SNS as CloudWatch Event Target

In this post, we’ll see how we can use Input Transformer while using SNS as CloudWatch Event target. This makes the mail we receive from SNS more readable.

Credit: https://medium.com/@rajesh007

Step 1: Create an SNS topic and subscription.

Step 2: Create a CloudWatch rule to get a notification whenever an instance state is changed. Set your SNS topic as target and under Configure input, select Input Transformer, and in the first text box, paste the following data to create some input variables.

{"instance-id":"$.detail.instance-id","state":"$.detail.state","time":"$.time","region":"$.region","account":"$.account"}

Now in the second text box, paste the following data which uses the variable we created to construct the actual message which SNS will send.

{ 
"An EC2 have just been" :<state>,
"Instance-id": <instance-id>,
"Instance State" : <state>,
"Time of event" : <time>,
"AWS Region" : <region>,
"AWSAccount" : <account>,
"Please take a look if you where not expecting any instance": <state>
}

Step 3: Now our setup is ready and we can test it by launching a few instances or starting/stopping an already existing instance.

Once the CloudWatch rule is triggered, you should be getting a mail like this:

👋 Join us today !!

️Follow us on LinkedIn, Twitter, Facebook, and Instagram

https://avmconsulting.net/

If this post was helpful, please click the clap 👏 button below a few times to show your support! ⬇

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store