A topic in SNS is a logical access point in communication between publisher and subscriber. Topic receives the message from publisher and filter it with SNS message filtration and delivered to the subscribers who have subscribed to that topic.
As like other services in AWS, topic is also identified with unique amazon resource name (ARN). To know more about Topic & SNS, refer What is SNS?
In this article, we would create our first topic and would subscribed to it.
Create a Topic
1. Sign into AWS Console (link) and Open SNS Service
2. Provide a Name to your Topic and click on Next
You could also click on Start with an overview like below to open the SNS Dashboard and then could click on Topics to create your topic.
3. Now in Create Topic page, you need to fill up couple of information’s
Display Name (Optional) – This is useful when you use this topic for SNS subscription. Maximum 100 characters are allowed. However, only first 10 characters would be used for SMS subscription.
Encryption (Optional) – By default its disabled. Encryption helps to encrypt your data at rest in SNS using Customer Master Key (CMK).
Access Policy (Optional) – This defines who could access to your topic. You need to update the topic policy if you want to allow other service to access it. By default only account owner have privilege to publish or subscribe the topic.
Delivery Retry Policy HTTP/HTTPs (Optional) – This policy is useful when SNS needs default settings change such as number of retries, retries with out delay, min. delay, max. delay, min. delay retries, max. delay retries, maximum receive rate to delivery the message to HTTP/HTTPs endpoint. AWS SNS allows you to create a topic with default settings for test/dev environment.
Delivery Status Logging (Optional) – You could use this feature to configure the logging of message delivery status to CloudWatch logs. The different protocol supports for these are Lambda, SQS, HTTP/HTTPs, Application endpoint
Tag (Optional) – You could assign a tag name as key-value pair to your topic for metadata management.
We would proceed with default Topic settings here
4. Click on Create Topic
This would create your first topic in AWS to establish the channel between source and target.
Now you need to subscribe an endpoint. Then you would be able to publish the message to the topic.
5. Click on Create Subscription
Topic ARN – Copy your topic ARN which you created in previous step and paste in Topic ARN of create subscription page.
Protocol – As we discussed in earlier posts, SNS supports different protocols to subscribe. We would select Email here and provide an email address to receive notification from SNS
Subscription Filter Policy (Optional) – This is used by SNS to filter the message send by Publisher.
Redrive policy dead-letter queue (Optional) – By default its disabled. However you could enable it to send undeliverables messages to SQS queue.
6. Request for Subscription
Once you created the Subscription it would show you the status as Pending Confirmation. Thereafter, you need to confirm it and then you would be able to Publish the message
Now go to your Subscription dashboard, select your subscription and apply for Request Confirmation
Once you clicked, it would display Confirmation request was sent successfully to your protocol.
7. Confirm Your Subscription
Go to your mail box, and click on the confirm subscription link provided by AWS.
8. Verify the Subscription Status
Refresh your Subscription Dashboard and you would be able to see that your subscription status has been confirmed.
Publish a Message
You are set with your topic and subscription creation and confirmation. Now you could proceed to publish a message.
1. Go to your Topic dashboard and select your topic
2. Click on Publish Message
3. Publish Message to your Subscriber
You could provide a Subject which is optional and could write a message in message body
You could also opt for Message Attributes for providing structured metadata items such as timestamps, signature etc
Now click on Publish Message to publish the message to your topic.
4. Verify the Message
You are successfully able to publish a message to your topic.
Please do like and comment below for any questions related to this article.