Create Lambda Function to handle the SNS Messages

Create Lambda Function to handle the SNS Messages

Know how lambda executes whenever there is a new topic in SNS
Clock Icon2022.10.14

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Introduction

Hemanth of Alliance Department here. In this blog, I will explain how the lambda function executes whenever there is a new topic in SNS.

AWS

Is a secure cloud service platform that offers compute power, database storage, content delivery, network, and other functionality to help businesses scale and grow. It is one of the first cloud vendors to start services in the year 2006. It offers all the 3 service models namely IAAS, PAAS, and SAAS. Some of the notable domains in AWS are Compute, Migration, Storage, Network and Content Delivery, Management Tools, Database, Messaging, Security and Identity Compliance, and many more.

SNS

A fully managed messaging service for both application to application and application to person. A2A pub/sub functionality provides topics for high-throughput, push-based, many-to-many messaging between distributed systems, microservices, and event-driven serverless applications. The A2P functionality enables you to send messages to users at scale via SMS, mobile push, and email.

AWS Lambda

A Serverless compute service that runs code as a reply to events and automatically takes care of the bottom resources. It runs code on high availability compute infrastructure and performs all the administration of the compute resources. A few examples are HTTP requests vis Amazon API Gateway, changes to objects in S3, and many others.

Demo of the lambda function that handles SNS messages

In your AWS console search for SNS and go to topics then click on create topic Selecting the Standard type as it supports many more subscriber types, is more cost-effective and much faster than FIFO. Leaving other settings as default click on create topic Now searching for Lambda in the console and clicking on functions This time I'll be going with blueprint and searching for SNS I'll be choosing python3.8 and clicking configure Give a function name and select the SNS topic you created above. Doing so will give the necessary permissions for lambda to access the SNS topic. Now click on create function and keep other things default Making changes in the function code, by adding the message subject code and printing the subject and message to the logs Going to the test tab, give a test name save it and click on the test
Looking at the execution results and click on the details Check logs in the Cloudwatch console by clicking logs Now testing with a real SNS message, go to the event click on "publish a message", type your message and click publish message
Going back and checking the logs

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.