<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alberto Marchetti</title>
    <description>The latest articles on DEV Community by Alberto Marchetti (@cmaster11).</description>
    <link>https://dev.to/cmaster11</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F89468%2F95dfa171-6fee-4f30-82e9-c31a3397cabc.png</url>
      <title>DEV Community: Alberto Marchetti</title>
      <link>https://dev.to/cmaster11</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cmaster11"/>
    <language>en</language>
    <item>
      <title>Track your infrastructure events with AWS SNS and Notify17</title>
      <dc:creator>Alberto Marchetti</dc:creator>
      <pubDate>Fri, 30 Apr 2021 16:07:40 +0000</pubDate>
      <link>https://dev.to/cmaster11/track-your-infrastructure-events-with-aws-sns-and-notify17-1091</link>
      <guid>https://dev.to/cmaster11/track-your-infrastructure-events-with-aws-sns-and-notify17-1091</guid>
      <description>&lt;p&gt;&lt;a href="https://aws.amazon.com/sns/" rel="noopener noreferrer"&gt;AWS SNS&lt;/a&gt; is a widely used notification service for messages coming from a multitude of AWS services, like EC2, SQS, Lambda, CloudWatch, and so on.&lt;/p&gt;

&lt;p&gt;SNS can be used pretty easily to let you know what happens around your infrastructure. Let's look at some use-cases, where you may need to get a message:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A CloudWatch alarm has turned into &lt;code&gt;ALERT&lt;/code&gt; state, you should definitely know that, check &lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ConsoleAlarms.html" rel="noopener noreferrer"&gt;SNS for CloudWatch docs&lt;/a&gt; or &lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-and-eventbridge.html" rel="noopener noreferrer"&gt;EventBridge docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;An EC2 instance needs replacement, which means it's most likely to stop working soon! Set up an SNS alert by following &lt;a href="https://aws.amazon.com/premiumsupport/knowledge-center/cloudwatch-notification-scheduled-events/" rel="noopener noreferrer"&gt;CloudWatch docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Any custom code you run in your EC2 instances or Lambda functions can generate an SNS message with &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-services-sns.html#cli-publish-sns-topic" rel="noopener noreferrer"&gt;one simple command&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of these cases share the fact that you need to be alerted because of an event, and that this event is meaningful for your infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You know what makes a difference? The location where you receive these alerts.&lt;/strong&gt; There is a fine line between being properly ready to act when an alert comes up, and ending up forgetting about it (don't we know how many blood emails we get all the time, and how many we just lose in the history?).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://notify17.net/" rel="noopener noreferrer"&gt;Notify17&lt;/a&gt; has been my answer to the issue of losing alerts on the way. Notify17 is a mobile app where you can centralize notifications from a multitude of sources: as long as you can generate a webhook, an HTTP request, you can get a notification on your phone.&lt;/p&gt;

&lt;p&gt;Notify17 also integrates seamlessly with AWS SNS! This means that you can create an SNS HTTPS endpoint straight to a Notify17 raw API key or notification template, without the need to manually confirm the subscription.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotwjp3hu4g5p59rkzclu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotwjp3hu4g5p59rkzclu.png" alt="A simple SNS flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Can you give me an example?
&lt;/h2&gt;

&lt;p&gt;Yes! You can experiment with AWS SNS topics and Notify17 by cloning and deploying the &lt;a href="https://gitlab.com/notify17-examples/aws-sns-terraform-example" rel="noopener noreferrer"&gt;https://gitlab.com/notify17-examples/aws-sns-terraform-example&lt;/a&gt; repository.&lt;/p&gt;

&lt;p&gt;In that example repository you can find a terraform project, which shows you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to create an SNS topic (&lt;a href="https://gitlab.com/notify17-examples/aws-sns-terraform-example/-/blob/75863a80f1e03826008832c66c8c6caa3112dac8/aws_sns_hook_raw.tf#L19" rel="noopener noreferrer"&gt;&lt;code&gt;aws_sns_topic&lt;/code&gt;&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;How to connect SNS with Notify17 (&lt;a href="https://gitlab.com/notify17-examples/aws-sns-terraform-example/-/blob/75863a80f1e03826008832c66c8c6caa3112dac8/aws_sns_hook_raw.tf#L34" rel="noopener noreferrer"&gt;&lt;code&gt;aws_sns_topic_subscription&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;How to generate simple notifications, once the SNS topic exists (&lt;a href="https://gitlab.com/notify17-examples/aws-sns-terraform-example/-/blob/75863a80f1e03826008832c66c8c6caa3112dac8/aws_sns_hook_raw.tf#L58" rel="noopener noreferrer"&gt;script&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;How to generate notifications, via &lt;code&gt;Lambda -&amp;gt; SNS -&amp;gt; Notify17&lt;/code&gt; (&lt;a href="https://gitlab.com/notify17-examples/aws-sns-terraform-example/-/blob/75863a80f1e03826008832c66c8c6caa3112dac8/lambda.js" rel="noopener noreferrer"&gt;lambda function&lt;/a&gt;, &lt;a href="https://gitlab.com/notify17-examples/aws-sns-terraform-example/-/blob/75863a80f1e03826008832c66c8c6caa3112dac8/aws_sns_hook_raw.tf#L118" rel="noopener noreferrer"&gt;script&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The general concept is that &lt;strong&gt;you can trigger SNS notifications from any kind of AWS resource&lt;/strong&gt;, and be notified immediately on your mobile phone.  If you use AWS CLI, this is an example of a command you can run to generate SNS notifications from any client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws sns publish &lt;span class="se"&gt;\ &lt;/span&gt; 
  &lt;span class="nt"&gt;--region&lt;/span&gt; us-east-1 &lt;span class="se"&gt;\ &lt;/span&gt; 
  &lt;span class="nt"&gt;--topic-arn&lt;/span&gt; &lt;span class="s2"&gt;"arn:aws:sns:us-east-1:123456789012:n17-example-aws-sns-test-hook-templated"&lt;/span&gt; &lt;span class="se"&gt;\ &lt;/span&gt; 
  &lt;span class="nt"&gt;--message&lt;/span&gt; &lt;span class="s2"&gt;"Hello!"&lt;/span&gt;

&lt;span class="c"&gt;# Optionally you can also use&lt;/span&gt;
  &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--subject&lt;/span&gt; &lt;span class="s2"&gt;"Notification title"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
  &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--message-attributes&lt;/span&gt; &lt;span class="s1"&gt;'{"myKey1":{"DataType":"String","StringValue":"Mr. Anderson"}}'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Just give me a notification template!
&lt;/h2&gt;

&lt;p&gt;If you just want to get started with Notify17 and SNS, you can import the following notification template, to catch all possible SNS messages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Import the template into Notify17.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;https://hook.notify17.net/api/template/TEMPLATE_API_KEY/sns&lt;/code&gt; as &lt;code&gt;HTTPS&lt;/code&gt; endpoint for your SNS topic.&lt;/li&gt;
&lt;li&gt;Publish and receive your SNS notifications!.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: you can find more info about AWS SNS and Notify17 in the &lt;a href="https://notify17.net/use-cases/aws-sns/" rel="noopener noreferrer"&gt;docs&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fnotify17.net%2Fimages%2Fnotification-template-import-only.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fnotify17.net%2Fimages%2Fnotification-template-import-only.png" alt="How to import"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;SNS catch-all&lt;/span&gt;  
&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;  
  &lt;span class="s"&gt;{{   &lt;/span&gt;
    &lt;span class="s"&gt;default  &lt;/span&gt;
      &lt;span class="s"&gt;(  &lt;/span&gt;
        &lt;span class="s"&gt;printf   &lt;/span&gt;
        &lt;span class="s"&gt;"SNS message - %s"   &lt;/span&gt;
        &lt;span class="s"&gt;(last (splitList ":" .TopicArn))  &lt;/span&gt;
      &lt;span class="s"&gt;)   &lt;/span&gt;
      &lt;span class="s"&gt;.Subject   &lt;/span&gt;
  &lt;span class="s"&gt;}}  &lt;/span&gt;
&lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|-&lt;/span&gt;  
  &lt;span class="s"&gt;{{ if isJson .Message }}  &lt;/span&gt;
  &lt;span class="s"&gt;{{/* Decode the message and dump its content */}}  &lt;/span&gt;

  &lt;span class="s"&gt;{{ dump (parseJson .Message) }}  &lt;/span&gt;

  &lt;span class="s"&gt;{{ else }}  &lt;/span&gt;
  &lt;span class="s"&gt;{{/* This is a normal text message */}}  &lt;/span&gt;

  &lt;span class="s"&gt;{{ .Message }}  &lt;/span&gt;

  &lt;span class="s"&gt;{{ if .attributesMap }}  &lt;/span&gt;
  &lt;span class="s"&gt;{{/* If we have any attributes, let's show them */}}  &lt;/span&gt;
  &lt;span class="s"&gt;Attributes: {{ dump .attributesMap | nindent 2 }}  &lt;/span&gt;
  &lt;span class="s"&gt;{{ end }}  &lt;/span&gt;

  &lt;span class="s"&gt;{{ end }}  &lt;/span&gt;
&lt;span class="na"&gt;testFieldType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yaml&lt;/span&gt;  
&lt;span class="na"&gt;testBodyYAML&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|-&lt;/span&gt;  
  &lt;span class="s"&gt;Message: Hello there!  &lt;/span&gt;
  &lt;span class="s"&gt;MessageAttributes:  &lt;/span&gt;
    &lt;span class="s"&gt;name:  &lt;/span&gt;
      &lt;span class="s"&gt;Type: String  &lt;/span&gt;
      &lt;span class="s"&gt;Value: General Kenobi  &lt;/span&gt;
  &lt;span class="s"&gt;MessageId: 88302c8d-9d71-514c-bbb8-746c487fde28  &lt;/span&gt;
  &lt;span class="s"&gt;Subject: Greetings!  &lt;/span&gt;
  &lt;span class="s"&gt;Timestamp: 2021-04-26T03:01:02.694Z  &lt;/span&gt;
  &lt;span class="s"&gt;TopicArn: arn:aws:sns:us-east-1:123:test-sns-template  &lt;/span&gt;
  &lt;span class="s"&gt;attributesMap:  &lt;/span&gt;
    &lt;span class="s"&gt;name: General Kenobi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>devops</category>
      <category>monitoring</category>
      <category>notify17</category>
      <category>aws</category>
    </item>
  </channel>
</rss>
