C1 – Create an SNS Topic

Photo by Thanhy Nguyen on Unsplash

Notification of events is key to basic monitoring, in this missive we will examine how to setup a basic AWS SNS topic to send an email whence invoked.

This will form a basic part of our simple monitoring system, and will be used in a number of oncoming missives.

I recommend one examine the AWS SNS documentation.

One can create an SNS topic in a number of ways, we will examine two of these, via the management console and via the AWS CLI.

From the management console:

Step 1: Log into the management console. Search for SNS

Step 2: From the SNS Dashboard Select Topics:

Step 3: In the Topics Panel, select Create Topic:

Step 4: Create the topic:

We will select Standard, enter a topic name, and set a friendly name, thence select create topic.

Step 5: Note Results, Specifically the ARN, (Amazon Resource Name)

Note the ARN, and then create a subscription.

Step 6: Create a SNS topic subscription.

In the protocol box select either email or email-JSON, enter an email address to receive the notifications, and click create subscription.

The difference betwixt email and email-JSON is the formatting of the email body.

Step 7: Confirm the Subscription

NOTE: The email address will receive an email with a link that must be clicked on to confirm the subscription.

One can view subscription status by clicking on the subscriptions tab in the left panel of the SNS dashboard.

From the CLI:

Step 1: Create the Topic

$ aws --region us-east-1 --profile default sns create-topic --name C1-SNS-EMAIL
{
    "TopicArn": "arn:aws:sns:us-east-1:XXXXXXXXXXXXXXXXXXXXX:C1-SNS-EMAIL"
}

This uses the CLI command SNS.create-topic. There few options but a review of the command reference is suggested.

DO NOTE THE TOPIC ARN.

Step 2: Create the subscription to the topic arn cretated prior:

aws --region us-east-1 --profile default sns subscribe --topic-arn arn:aws:sns:us-east-1:XXXXXXXXXXXX:C1-SNS-EMAIL --protocol email --notification-endpoint crawls@techhell.org
{
    "SubscriptionArn": "pending confirmation"
}

Note the pending confirmation status. Confirmation of the subscription continues as described prior.