Serverless, or more specifically in the AWS world, Lambda, seems to be the buzzword recently. So, I decided to give it a try. Getting an appropriate use-case is the difficult one. A simple Hello World tutorial wouldn’t give you enough exposure. Hence, after much thoughts, I decided to try to “Lambda”-dize (convert existing backendful service to a Lambda function) a function to send email notification upon contact form’s submission from my static website. Not to complex but not to simple either.
- Familiarity with the AWS Console
- Basic knowledge of IAM (e.g. Role/ Policy), S3, and SES
Setting Up Your Lambda Function
Follow the steps here: https://github.com/eleven41/aws-lambda-send-ses-email
Some helpful pointers/ resources:
- Creating a New Policy Using Policy Editor
- When creating the deployment package, go to the SendSesEmail folder of the downloaded zip and type
npm installin the Terminal
- When zipping the deployment package, make sure you zip the content files instead of the SendSesEmail directory.
- Follow the instructions here to create a lambda function. But instead of writing the code in the web editor, opt to upload your zip file.
The Lambda function needs to be exposed as a RESTful service. Here’s where API Gateway comes into the picture. Steps can be found below:
SES is only available in selected regions. At first, I tried with ap-southeast-1 region Singapore and encountered region not available issue. At the end, I decided to host everything in us-east-1.
Make sure to run
npm installto download all the dependencies before zipping your deployment package. You will encounter ‘markup-js’ not found error if you don’t.
Make sure you zip the content files instead of the directory when creating the deployment package.
Somehow sending to a Yahoo mail server doesn’t work with SES sandbox that well. My GMail account has no problem though.