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. Jus…


This content originally appeared on DEV Community and was authored by Yash Sonawane

"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:

  1. API Gateway receives the request (HTTP POST)
  2. Lambda processes the form data
  3. 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

  1. Go to SES Console → Email Addresses
  2. Click Verify a New Email Address
  3. Enter your receiving email (e.g. yourname@gmail.com)
  4. 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

  1. Go to API Gateway Console → Create API
  2. Choose HTTP API
  3. Add integration: Lambda function → sendContactForm
  4. Add route:
  • Method: POST
  • Path: /contact
    1. 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.


This content originally appeared on DEV Community and was authored by Yash Sonawane


Print Share Comment Cite Upload Translate Updates
APA

Yash Sonawane | Sciencx (2025-08-21T03:06:00+00:00) Build a Serverless Contact Form with Lambda + API Gateway + SES 📩. Retrieved from https://www.scien.cx/2025/08/21/build-a-serverless-contact-form-with-lambda-api-gateway-ses-%f0%9f%93%a9/

MLA
" » Build a Serverless Contact Form with Lambda + API Gateway + SES 📩." Yash Sonawane | Sciencx - Thursday August 21, 2025, https://www.scien.cx/2025/08/21/build-a-serverless-contact-form-with-lambda-api-gateway-ses-%f0%9f%93%a9/
HARVARD
Yash Sonawane | Sciencx Thursday August 21, 2025 » Build a Serverless Contact Form with Lambda + API Gateway + SES 📩., viewed ,<https://www.scien.cx/2025/08/21/build-a-serverless-contact-form-with-lambda-api-gateway-ses-%f0%9f%93%a9/>
VANCOUVER
Yash Sonawane | Sciencx - » Build a Serverless Contact Form with Lambda + API Gateway + SES 📩. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/08/21/build-a-serverless-contact-form-with-lambda-api-gateway-ses-%f0%9f%93%a9/
CHICAGO
" » Build a Serverless Contact Form with Lambda + API Gateway + SES 📩." Yash Sonawane | Sciencx - Accessed . https://www.scien.cx/2025/08/21/build-a-serverless-contact-form-with-lambda-api-gateway-ses-%f0%9f%93%a9/
IEEE
" » Build a Serverless Contact Form with Lambda + API Gateway + SES 📩." Yash Sonawane | Sciencx [Online]. Available: https://www.scien.cx/2025/08/21/build-a-serverless-contact-form-with-lambda-api-gateway-ses-%f0%9f%93%a9/. [Accessed: ]
rf:citation
» Build a Serverless Contact Form with Lambda + API Gateway + SES 📩 | Yash Sonawane | Sciencx | https://www.scien.cx/2025/08/21/build-a-serverless-contact-form-with-lambda-api-gateway-ses-%f0%9f%93%a9/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.