How to Build a Serverless App with S3 and Lambda in 15 Minutes

The Quickest Way to Make your Static S3 Website Dynamic

For those who use S3 to power their JavaScript heavy websites, this tutorial will teach you how you can add server side functionality-like processing forms and running functions accordingly-to your S3 website within a few minutes — all without provisioning, paying for, or managing any servers.

In many cases, S3 is simply a part of application architecture and the server side of the application runs on an Elastic Compute Cloud (EC2) mounted EFS (filesystem) elsewhere. And in most cases, that is the best approach in terms of designing resilient, decoupled, scalable web applications. However, there are times when you don’t need so many AWS resources just to simply process some form data.

So here’s the fastest and most simple way to add some server side functionality to your S3 website. In this case, sending form submissions to your email address.

DISCLAIMER: If you are trying to build a full fledged web app in S3, this tutorial is not for you.

AWS tools we will be using:

Simple Storage Service (S3) — This is where your static website is hosted and where all of your HTML, CSS, JavaScript and assets will live.

— This is where your static website is hosted and where all of your HTML, CSS, JavaScript and assets will live. API Gateway — Your S3 website will make an API call when a form is processed and when this call is made to API Gateway, it will trigger a Lambda function.

— Your S3 website will make an API call when a form is processed and when this call is made to API Gateway, it will trigger a Lambda function. Lambda — The Lambda function can do whatever you want but in our case, it simply sends the data from the form to an email address using AWS Simple Email Service (SES)

Step 1: Create your API endpoint

Open API Gateway and click Create New API

Step 2: Select Actions->Create Method

Step 3: Select “POST” as method type and click the checkmark

Step 4: Select Lambda as well as the Lambda function created in the next part of this tutorial

Step 5: Give permissions to API Gateway to invoke Lambda

Step 6: Click Actions->Deploy API

Step 7: Select New Stage and name your stage

Step 8: Now you have your endpoint URL!

Step 9: Don’t forgot to enable CORS. Now on to Lambda!

What did we just do? In this section we built the API that will allow your formerly static S3 website to call Lambda functions.