Using SAM for a small-business website

A spring sunset as seen from “Sto Psito” Restaurant.

As some of you might already know, my dad owns and runs a restaurant back in my hometown of Argostoli, Greece. As you might expect, given my inclination in Tech, I have been responsible for creating and maintaining the “digital presence” of the restaurant since a young age.

Although it might not sound very exciting, I was able to make the website my playground and I got to experiment with various technologies and programming languages that I was interested in.

Recently, I started hearing good things about the Serverless Application Model (SAM) and how exciting it is. After a bit of reading I decided to see what all the fuss was about..

So here’s the question: Can a small restaurant website run on the serverless model? 🤔

Requirements

  • Global availability
  • Less than 2s load time
  • Fully encrypted communications (SSL)
  • Simple reservation system
  • Keep the costs at bare minimum!

Solving the problem

If you define the problem correctly, you almost have the solution. — Steve Jobs

Serving the website

Not a bad place to code! 🍺

Since the content does not change very often and the menu is only updated once every year, I decided that we don’t need a CMS. Instead, every single page is a static HTML file and all the dependencies such as Bootstrap or Font Awesome are loaded using a CDN instead of hosting them.

Since the website is completely static, it lives in an S3 bucket instead of a server, which reduces the running costs dramatically.

By adding Cloudflare into the mix the website can benefit even further. The free version of Cloudflare provides a SSL certificate out of the box which is more than enough since we only maintain a single domain. More importantly, we rely on their CDN network in order to deliver the website extremely quickly no matter where the request is coming from. Cloudflare makes copies of the website across their global network and uses the edge server nearest to the user to deliver the website.

Distribution and delivery of the website using S3 & Cloudflare.

Making the website useful

Users can now see the website but that’s all they can do at the moment. As previously mentioned, there is no backend application server processing requests or persisting data. So how can a user reserve a table to enjoy the summer sunset over a glass (or 7) of wine?

Why use a server when we can leverage AWS Lambda? It allows us to execute code without provisioning or managing servers. AWS charges only for the compute time we consume which is in the factor of milliseconds. In addition, 1 million requests per month are completely free!

So how does it work?

Overall, the reservation request is a 3 step process.

Firstly, a reservation request is made to an API Gateway endpoint which triggers a λ that writes the reservation in a DynamoDB table for persistence. When the reservation is saved in Dynamo, another λ starts and publishes a message with the reservation details to a SNS topic. Finally, the message is consumed by various λ functions that send out emails and text messages.

This is what happens when you click the “Reserve Table” button in the website.

Results

But is all that really worth it? Should a small business invest money and effort in a SAM infrastructure? Here’s what we’ve discovered:

  • The website has hundreds of unique visitors every month, with 100% uptime thus far. Cost: $0.
  • Average time for full-rendering of the website is less than 1s. Cost: 0$.
  • Secure connections. Cost: $0
  • Table Reservation system. Cost: 0$.

Since we switched to a completely serverless model, the total cost for running a profitable website has $0!

Of course, each business has a different set of requirements and needs, but in my opinion SAM can promote cost reduction without degrading the service.

Thanks for reading!


The infrastructure is built using Cloudformation and the λ functions are written in Go. You can find all the code on my Github.