One of the greatest services provided by AWS is Lambda. In a single sentence and as stated on the official AWS page:
Lambda lets you run code without provisioning or managing servers
How’s that possible? Well, as the reader probably knows already:
So basically Lambda let’s you define a piece of code that executes a specific functionality, following a defined signature (more on that later). Then whenever you want, you can tell AWS to execute your function and the magic will happen. The magic is basically Amazon allocating some resources in their cloud infrastructure to execute that piece of code you wrote.
The great thing about this, is that you can build specific server side functionality without the need of managing a server yourself. AWS will take care of allocating the needed resources for your Lambda function to execute successfully.
The email use case
As a software development company, at XOOR we build websites and web applications for many different purposes. But among all of them, one very common use case is the typical contact form on a company website. It happens that company websites are usually fully static, meaning that we don’t need a web server as we already explained in this post. But whenever you want to add some extra functionality to the website, like a contact form where people can reach out to you, you end up needing some backend code to take care of the email sending.
What happens is that setting up a whole web server for the purpose of sending a few emails every day feels a lot like killing a fly with a sledgehammer… So why not define this behavior in a Lambda function that will execute only when someone uses our contact form, and thus reducing costs as Amazon will charge only based on the resources used by the function execution. Sounds like a plan? Then let’s stop the chatter and let’s see how to set that up.