AWS with SNS (simple notification service) and SQS (simple queue service) and Lambda Functions

Reginald Bratton
5 min readOct 29, 2023

--

[You’ve got mail!]

Lets revisit our project where we re-vamped Karl’s K-9 Kennel website to ensure it was highly-available. Link can be found here:

We used AWS CloudFront, AWS WAF, Amazon Inspector, EC2(Web servers) and AWS Aurora Serverless in attached lesson.

Now we are going to visit AWS SNS and SQS what are they and how they can help Karl as well.

AWS SNS(Simple Notification Service)

Amazon SQS(Simple Queue Service)

Revamping a website we could use SQS and SNS hand-in-hand.

Our client Karl and his dog business. The API gateway is an API management tool that sits between a client and a collection of backend services. An API Gateway acts as a reverse proxy to accept all application programming interface (API) calls, aggregate the various services required to fulfill them, and return the appropriate result. Think of the API Gateway as the connector between the client (Karl) and the resources on AWS.

Next Up is Our AWS Lamba…Using Lamba is a compute service for application scenarios that need to scale up rapidly, and scale down to zero when not in demand. With Karl’s website when he would have spike in traffic(scalability) when a new litter of puppies were available. Lambda scales up for you and back down when the resources are not needed.

Quick example, you can use AWS Lambda to notify AWS SNS for multiple use cases. Suppose you want to send out an email whenever new puppies were available or a new services are added to the website.

AWS Lambda

For this, whenever new dogs are added to the database, an AWS Lambda function will trigger which will notify Amazon SNS. This, in turn, will send mass emails to the perspective buyers and customers who have paid their membership subscription dues. If you are Karl this definitely helps grow your business and keeps your customers informed.

Amazon SQS keeps your business architecture available. Think back to revamping a website with Karl. Now we have requests for a special service that he provides where Karl gives our dog-walking tips. Since business has been booming well are multiple clients that would like some dog walking tips for a recently purchased puppy.

The Users would be the clients that have purchased dogs or perspective new clients requesting info on dogs/services. Those users would visit the website that is hosted on the EC2 instance/Webserver. After completing the request it would go into a request request queue. The request would be processed by the Auto Scaling Group where if you need more CPU, RAM, Memory it would automatically create more resources for you. After the request has been processed now a response is sent back to the queue and back to the Web Server(EC2 instance).

New Concept Alert!

If you picked up your phone right now to call a friend John. If John has a dead battery the call can not be completed obviously but John’s dead battery does not affect my cell phone and the usage that is available to me this would be a example of Decoupling (Yes John might or might not have voicemails but he cannot see the messages if his phone is off because of the dead battery). Creating a monolithic application and decoupling it would mean just because John has a dead battery it would not affect the functionality of my phone. One thing is not dependent on the other thing. (Two-De-coupling)

I need to ensure that no matter what I can receive requests from our customers who are looking to purchase or requesting info and if there is nobody available to take the request it doesn’t stop customers from making requests. The more request can make my request queue larger then as soon as they are handled the queue scales back down.

Lets dig a little deeper:

Another example could be:

If I owned a coffee shop and customers were ordering latte after latte the drink orders would head to the queue. I would have the cashier taking the request and a barista making the drinks. Decoupling would involve the process of if there was no barista available that would not stop customers from making drink orders and having the order accepted in our queue. If my barista was out on break or my shop is understaffed the cashier could wait until you have 3–4 drink orders and the cashier could make the drinks until the barista comes back available. This is not the most efficient but it could work for smaller drink orders but the SQS service allows customers to keep placing orders of coffee without interruptions.

We mentioned before with or without barista that Queue of drink orders will grow and grow which is great for your business like a Starbucks Or Chipotle. But if you take out the barista you could have the cashier make the drink. With the advent of technology with online orders you might not have a cashier for in-person orders. You will just have one person making the drinks/food (handling requests) for the queue and customers can place orders in person with no human interaction which pushes all of their orders to a queue.

No cashier… customers pushing orders straight to a queue.

Thanks for reading my post where we helped Karl set up Amazon SNS messages and how Amazon SQS helped his business along with comparable examples.

Key terms visited: SNS, SQS, Decoupling, Lambda Functions

Lets Connect :) https://www.linkedin.com/in/reginald-bratton-388a0754/

--

--