Tuesday, 14 July 2020

SNS with lambda

SNS with lambda

SNS: Simple Notification Service.

This is useful to create push notifications to the customer based on the topic which customer subscribed.For ex: Banking alerts , Promotional offers etc.

Topic: Intended subject which customer selected to get an update/alert.

For ex: If we have uploaded or modified any object which is stored in S3, you have to get an alarm/alert , to execute this kind of feature AWS provides Simple Notification Service feature to achieve it.

Also if there is modifications in Database where your external servers/customers should have to get an update , to achieve this as well , SNS will be utilized.



Steps to to create a topic in SNS
1.Search for services in AWS dashboard, select SNS
2.Create a topic by giving topic name
3.If you want to encrypt your message use the section:Encryption - optional
4.Access policy: This is the policy where we can provide the subscription on various categories like only to the owner, Everyone , Only with certain accounts or only with certain end points Under Basic Policy.
Advanced Plan:  An access policy will be created by using the JSON object.

5. Delivery retrieve policy:
When we configure a SNS topic , the server will push a notification with number of retrieves and with minimum and maximum delays .
6.Delivery status logging:
This will give us the delivery status of the messages which we sent , this log will be stored in Cloud watch.
7.Tags: This will allow you to filter a topic which will allow you to identify when you have number of topics.

So for now we just entered topic name and selected default values and clicked on create topic.


ARN: AWS Resource Number, which is the unique key created by AWS.

So to create a subscription , we are using Lambda . 

Click on "Create a Function" --> click on SNS with python --> fill as below
In above screen, select topic which we created earlier under SNS trigger
Then no need to modify python code and click on "Create function".

Once after Lambda function created , we can go to SNS and we can see function is associated with SNS as a subscription topic. Now click on publish message.



Now the Clodwatch having logs of your Lambda function  , you can see log messages there.

No comments:

Post a Comment