AWS SNS
Amazon Simple Notification Service (SNS) is a highly available, durable, secure, fully managed pub/sub messaging service that enables you to decouple microservices, distributed systems, and serverless applications.
Additionally, SNS can be used to trigger notification end users using mobile push, SMS, and email.
Source : Official
Within this post, we will cover.
- How to create SNS Topic and attach Email Subscribers to it via AWS Console.
- How to create SNS Topic and attach Email Subscribers to it via AWS CloudFormation script.
We will start with the use case:
- If you want to trigger email notifications coupled to any AWS services like AWS lambda function.
- If you want to fan out AWS lambda function via SNS.
Steps:
Create SNS Topic using AWS Console.
- AWS Console --> SNS --> Create Topic --> Fill detail and Create Topic.
- Topic Name : Identifier of topic name, could be anything.
- Display Name : This one is important, when Notification email will land to your email this will be the name for the SNS email, so keep so that it will give you a hint about the notification content.
Attach email subscribers to SNS Topic and Verify the Subscription.- Under above created SNS topic, scroll down and Click on Create Subscription
- Fill in the below required details and create Subscriptions.
- Topic ARN --> Selected by default.
- Protocol --> Email.
- Endpoint --> Email address of recipient, if you want notification to your inbox put your email id.
- Verify Subscription --> You will get a AWS Notification - Subscription Confirmation email.
- Click on the link to confirm subscription.
- With respect to filled input within screenshot, something similar you can expect.
- SNS Topic ARN can be used later to send email notifications or fan out Lambda.
Note : Every time you want to send to notification to new email address, repeat the above process to add Subscriber under same SNS Topic.Yeah above are the steps to create SNS topic and add subscribers via Console, below is the AWS CloudFormation Script to SNS topic and add email Subscribers to it.
AWS CloudFormation Script.
AWSTemplateFormatVersion: 2010-09-09Description: CFN to create SNS topic and Add two different email Subscribers to it. Parameters: SNSTopicName: Type: String Description: Provide SNS Topic Name SNSTopicDisplayName: Type: String Description: Provide SNS Topic's Display Name, will be used as a name for SNS emails. SubscriptionEmail: Type: String Description: Provide DL or email for your SNS Topic.
Resources: SNSTopic: Type: AWS::SNS::Topic Properties: TopicName: !Sub ${SNSTopicName} DisplayName: !Sub ${SNSTopicDisplayName} Subscription: - Endpoint: !Sub ${SubscriptionEmail} Protocol: email
In case if we want to add more email subscribers, we can append more -Endpoint and Protocol as email to it.
Below one is the hard coded Resource for SNS topic with two email subscribers,
Resources: SNSTopic: Type: AWS::SNS::Topic Properties: TopicName: mySNSTopic DisplayName: SNS Admin Subscription: - Endpoint: admin@cyberkeeda.com Protocol: email Subscription: - Endpoint: blogger@cyberkeeda.com Protocol: email
- Under above created SNS topic, scroll down and Click on Create Subscription
- Fill in the below required details and create Subscriptions.
- Topic ARN --> Selected by default.
- Protocol --> Email.
- Endpoint --> Email address of recipient, if you want notification to your inbox put your email id.
- Verify Subscription --> You will get a AWS Notification - Subscription Confirmation email.
- Click on the link to confirm subscription.
- With respect to filled input within screenshot, something similar you can expect.
- SNS Topic ARN can be used later to send email notifications or fan out Lambda.
AWSTemplateFormatVersion: 2010-09-09
Description: CFN to create SNS topic and Add two different email Subscribers to it.
Parameters:
SNSTopicName:
Type: String
Description: Provide SNS Topic Name
SNSTopicDisplayName:
Type: String
Description: Provide SNS Topic's Display Name, will be used as a name for SNS emails.
SubscriptionEmail:
Type: String
Description: Provide DL or email for your SNS Topic.
Resources:
SNSTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: !Sub ${SNSTopicName}
DisplayName: !Sub ${SNSTopicDisplayName}
Subscription:
- Endpoint: !Sub ${SubscriptionEmail}
Protocol: email
Resources:
SNSTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: mySNSTopic
DisplayName: SNS Admin
Subscription:
- Endpoint: admin@cyberkeeda.com
Protocol: email
Subscription:
- Endpoint: blogger@cyberkeeda.com
Protocol: email
No comments:
Post a Comment