A Serverless Perspective on AWS SNS
What is AWS SNS?
AWS SNS (Amazon Simple Notification Service) is an Amazon Web Services product that provides cloud-based solutions for push messaging. It allows applications and websites to send notifications to mobile devices, email accounts, web servers, SQS queues, etc.
Why is SNS essential for a Serverless ecosystem?
- Send Mass Messages
A key benefit of AWS SNS is its speed and efficiency. Developers can quickly utilise SNS to deliver millions of messages in near real-time. It helps carry out batch processing, automation, and workflows that involve sending large messages.
- Flexibility With Message Content Formatting
When sending messages through AWS SNS, there are no restrictions on the format or amount of data included in the messages. It also supports multiple messaging protocols, such as HTTP, HTTPS, Email JSON, and SMS (text).
- Platforms Are Available On Many Devices
Today's consumers use many devices - phones, PCs, tablets, etc. - daily and interchangeably. The AWS SNS platform allows developers to quickly enable their app functionality across all these devices using a single codebase. They don't have to write separate versions or use distinct sets of codes for every platform available in today's multi-device world, effectively improving customer usability.
- Geographical Delivery Options
Beyond simply choosing the content formatting for your message groups, you can also target specific geographic regions when delivering messages through AWS SNS. When you are targeting a particular demographic – say only those located within, say, one city – this feature becomes extremely handy from both a money-saving and time perspective since you don't have to filter out who will receive particular messages from others manually.
There are several serverless tutorials available with AWS SNS and AWS Lambda to create one function.
When to use SNS vs. SQS
Amazon Simple Queue Service (SQS) is a messaging service that makes it easier for web applications and distributed systems components to communicate with each other over the Internet.
When To Use SNS
If you need reliable communication through multiple protocols: When you need to deliver a message reliably across multiple endpoints or devices, SNS allows you to send messages via HTTP callbacks, email, mobile push, and SMS uniformly. It eliminates the need for third-party code or custom APIs.
If you want fast real-time delivery of notifications: If you're interested in sending out notifications faster than serverless SQS can offer, then SNS is the way to go. Because it does not require polling for notification requests - it simply delivers notifications onto your app quickly and reliably - making it ideal for applications that require real-time updates or conversations like chat messages.
When To Use SQS
If your task requires total processing power than one machine can manage, serverless SQS scales up resources easily if needed down the line! Plus, extra overhead costs associated with scaling remain relatively low since the queue runs optimally on managed infrastructure, backed by a regional availability capability feature set offered only under the principal AWS product stack umbrella.
Much larger projects might require more processing time than single machines can provide. In these cases, leveraging queues may come in handy while still ensuring low price per unit output through the variable pricing model employed by Amazon Cloud provider's portfolio products.
SNS limitations
- No Way to Monitor Messages
As messages pass through the web, there is no way to guarantee if and when a message will get delivered. Besides, some notifications require an acknowledgment from the recipient for validation. This type of validation cannot be done with AWS SNS since there is no way of knowing if an intended audience received the message.
- Scalability
If your business proliferates, you may need more capacity than what AWS SNS provides to send notifications quickly and reliably. Furthermore, due to its limited scalability capabilities, it may need help handling specific specialised requests, such as high-speed or high availability.
- Support for Custom Routing Rulesets
Many businesses have specific requirements for delivering messages based on their target demographic or industry-specific needs. However, with AWS SNS, custom routing rulesets are not supported and must be created manually as part of the notification workflow setup process.
How to Trigger AWS Lambda Functions From AWS SNS Messages?
Create a Topic in Amazon SNS
To do this, open the Amazon SNS console and click "Create topic." You will receive a drop box for information about the topic, including its name, display name, and optional email wrapping and encryption settings. After filling in the required fields, click "create" to create the topic.
Configure Your Lambda Function
- Go into the AWS Lambda console and select your function from the list of existing lambda functions.
- Scroll until you see "Events Sources" and select "SNS" from the dropdown menu. You will then be able to select the appropriate topic and configure other parameters, such as batch size and maximum invocation count if needed.
- Click "add" to save your configuration changes for this event source.
Publish Messages via Your Topic
To do this, open up the Amazon SNS console again and select your newly created topic (it should appear in the list of topics under 'My Topics'). Selecting it should open a new window where you can publish messages by entering text into a text box labelled 'Message Body' - just like sending an email!
Once you hit send, that message should be queued up immediately in your topics' resulting queue, which consumers can then consume.
Test Your Configuration
After everything is set up correctly at this stage, it should be pretty easy to test whether or not our configuration worked correctly by calling on said function directly (to detect any errors generated earlier) or via automated testing methods.
Wrapping Up!
To sum up, AWS SNS is a robust and reliable serverless AWS service that offers a wide array of features and services to meet the needs of any organisation. AWS SNS is an easy-to-implement service that can scale according to the business needs while also providing an array of options to customise the notifications according to your preferences.