Build a Serverless Contact Form with Lambda + API Gateway + SES ๐ฉ

"Want to send emails from your website without running a server? Youโre 15 minutes away from magic."
Serverless architecture is a game-changer โ especially for simple, powerful features like contact forms. No more PHP mailers or backend servers. Just a few AWS services and you're good to go!
In this guide, weโll create a fully functional serverless contact form using AWS Lambda, API Gateway, and SES (Simple Email Service).
Letโs dive in and get your inbox buzzing. ๐
๐งฑ What We'll Build
A user submits a contact form on your static website. Hereโs what happens:
API Gateway receives the request (HTTP POST)
Lambda processes the form data
SES sends the email to your inbox
Like a digital postman that never sleeps.
๐ ๏ธ Prerequisites
AWS account with SES verified email
Basic knowledge of JavaScript and AWS Console
A static site (e.g., React, HTML, etc.) hosted on S3 or anywhere else
๐ Step 1: Verify Email in AWS SES
Go to SES Console โ Email Addresses
Click Verify a New Email Address
Enter your receiving email (e.g.
yourname@gmail.com
)Click verification link in the email
Done! SES can now send emails to (and from) that address.
๐ง Step 2: Create Lambda Function
Go to Lambda Console โ Create function โ Author from scratch
Name:
sendContactForm
Runtime: Node.js 18.x
Paste this sample code:
const AWS = require('aws-sdk');
const SES = new AWS.SES();
exports.handler = async (event) => {
const { name, email, message } = JSON.parse(event.body);
const params = {
Destination: {
ToAddresses: ['yourname@gmail.com'],
},
Message: {
Body: {
Text: { Data: `Name: ${name}\nEmail: ${email}\nMessage: ${message}` },
},
Subject: { Data: 'New Contact Form Submission' },
},
Source: 'yourname@gmail.com',
};
await SES.sendEmail(params).promise();
return {
statusCode: 200,
body: JSON.stringify({ message: 'Email sent successfully' }),
};
};
โ
Don't forget to update the ToAddresses
and Source
to your verified SES email.
๐ Step 3: Connect Lambda to API Gateway
Go to API Gateway Console โ Create API
Choose HTTP API
Add integration: Lambda function โ
sendContactForm
Add route:
Method: POST
Path:
/contact
Deploy and copy the Invoke URL
๐ Step 4: Connect Frontend to API
Example fetch call from your React or HTML form:
fetch('https://your-api-id.execute-api.region.amazonaws.com/contact', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: 'John Doe',
email: 'john@example.com',
message: 'Hey there, this is awesome!'
})
})
.then(res => res.json())
.then(data => console.log(data));
โ ๏ธ For public APIs, consider adding a CAPTCHA or throttling to prevent abuse.
๐งฐ Extras (Optional but Cool)
Add CORS support in API Gateway settings
Enable logging in CloudWatch for debugging
Use environment variables to store email addresses
Validate input fields on frontend AND backend
๐ You're Live!
You now have a production-grade, serverless contact form that:
Costs next to nothing
Scales automatically
Sends messages in seconds
And all this without managing a server. ๐
๐ฌ What Will You Use It For?
Your personal portfolio?
A client landing page?
A side project MVP?
๐ Drop your use cases or questions in the comments!
Smash that โค๏ธ if this helped you go serverless, and share it with someone who needs it.
Subscribe to my newsletter
Read articles from Yash Sonawane directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Yash Sonawane
Yash Sonawane
DevOps & Cloud Engineer | AWS, Docker, K8s, CI/CD Writing beginner-friendly blogs to simplify DevOps for everyone.