Track your infrastructure events with AWS SNS and Notify17
Tags: devops, monitoring, notify17, aws
Published: 2021-04-30 16:07:40

---
title: Track your infrastructure events with AWS SNS and Notify17
published: true
description: A simple approach to be notified about events happening in AWS!
tags: devops, monitoring, notify17, aws
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9gtmgpz9226t067jcm7.png
---

[AWS SNS](https://aws.amazon.com/sns/) is a widely used notification service for messages coming from a multitude of AWS services, like EC2, SQS, Lambda, CloudWatch, and so on.

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:

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

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.

**You know what makes a difference? The location where you receive these alerts.** 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?).

[Notify17](https://notify17.net/) 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.

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.

![A simple SNS flow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/otwjp3hu4g5p59rkzclu.png)

## Can you give me an example?

Yes! You can experiment with AWS SNS topics and Notify17 by cloning and deploying the [https://gitlab.com/notify17-examples/aws-sns-terraform-example](https://gitlab.com/notify17-examples/aws-sns-terraform-example) repository.

In that example repository you can find a terraform project, which shows you:

* How to create an SNS topic ([`aws_sns_topic`](https://gitlab.com/notify17-examples/aws-sns-terraform-example/-/blob/75863a80f1e03826008832c66c8c6caa3112dac8/aws_sns_hook_raw.tf#L19))
* How to connect SNS with Notify17 ([`aws_sns_topic_subscription`](https://gitlab.com/notify17-examples/aws-sns-terraform-example/-/blob/75863a80f1e03826008832c66c8c6caa3112dac8/aws_sns_hook_raw.tf#L34)
* How to generate simple notifications, once the SNS topic exists ([script](https://gitlab.com/notify17-examples/aws-sns-terraform-example/-/blob/75863a80f1e03826008832c66c8c6caa3112dac8/aws_sns_hook_raw.tf#L58))
* How to generate notifications, via `Lambda -> SNS -> Notify17` ([lambda function](https://gitlab.com/notify17-examples/aws-sns-terraform-example/-/blob/75863a80f1e03826008832c66c8c6caa3112dac8/lambda.js), [script](https://gitlab.com/notify17-examples/aws-sns-terraform-example/-/blob/75863a80f1e03826008832c66c8c6caa3112dac8/aws_sns_hook_raw.tf#L118))

The general concept is that **you can trigger SNS notifications from any kind of AWS resource**, 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:

```bash
aws sns publish \  
  --region us-east-1 \  
  --topic-arn "arn:aws:sns:us-east-1:123456789012:n17-example-aws-sns-test-hook-templated" \  
  --message "Hello!"

# Optionally you can also use
  [--subject "Notification title"]
  [--message-attributes '{"myKey1":{"DataType":"String","StringValue":"Mr. Anderson"}}']
```

## Just give me a notification template!

If you just want to get started with Notify17 and SNS, you can import the following notification template, to catch all possible SNS messages:

1. Import the template into Notify17.
2. Add `https://hook.notify17.net/api/template/TEMPLATE_API_KEY/sns` as `HTTPS` endpoint for your SNS topic.
3. Publish and receive your SNS notifications!.

Note: you can find more info about AWS SNS and Notify17 in the [docs](https://notify17.net/use-cases/aws-sns/)!

![How to import](https://notify17.net/images/notification-template-import-only.png)

```yaml
label: SNS catch-all  
title: |  
  {{   
    default  
      (  
        printf   
        "SNS message - %s"   
        (last (splitList ":" .TopicArn))  
      )   
      .Subject   
  }}  
content: |-  
  {{ if isJson .Message }}  
  {{/* Decode the message and dump its content */}}  
  
  {{ dump (parseJson .Message) }}  
  
  {{ else }}  
  {{/* This is a normal text message */}}  
  
  {{ .Message }}  
  
  {{ if .attributesMap }}  
  {{/* If we have any attributes, let's show them */}}  
  Attributes: {{ dump .attributesMap | nindent 2 }}  
  {{ end }}  
  
  {{ end }}  
testFieldType: yaml  
testBodyYAML: |-  
  Message: Hello there!  
  MessageAttributes:  
    name:  
      Type: String  
      Value: General Kenobi  
  MessageId: 88302c8d-9d71-514c-bbb8-746c487fde28  
  Subject: Greetings!  
  Timestamp: 2021-04-26T03:01:02.694Z  
  TopicArn: arn:aws:sns:us-east-1:123:test-sns-template  
  attributesMap:  
    name: General Kenobi
```