DEV Community

Cover image for How I Built a Serverless Contact Form and Scalable Backend with AWS Lambda, Fargate, and Batch
PETER Samuel
PETER Samuel

Posted on

How I Built a Serverless Contact Form and Scalable Backend with AWS Lambda, Fargate, and Batch

In this article, I document a real-life, fully practical AWS serverless application that covers key services including Lambda, API Gateway, SNS, ECS with Fargate, and AWS Batch. I took a bottom-up approach with screenshots, real configurations, and working examples—starting with a simple serverless contact form and ending with automated job processing.

Overview of What I Built

A contact form on the frontend integrated with AWS Lambda and API Gateway

Notifications sent via SNS to my email inbox

A Docker-based backend app deployed using ECS and Fargate

A scheduled AWS Batch job that runs a report-generating script

All components were built from scratch with secure access and IAM configurations

Step 1: Build a Contact Form with Lambda, API Gateway, and SNS

  1. Create a Lambda Function Service: AWS Lambda

Runtime: Python 3.12

Code:
import json
import boto3

def lambda_handler(event, context):
sns = boto3.client("sns")
sns.publish(
TopicArn="arn:aws:sns:your-region:your-account-id:YourTopicName",
Message="You've received a new contact form message.",
Subject="New Contact"
)
return {
"statusCode": 200,
"body": json.dumps("Message sent successfully.")
}
Deploy the function after writing the handler code

2. Create SNS Topic

Service: Simple Notification Service (SNS)

Name: ContactFormTopic

Create a subscription (Email)

Confirm the subscription from your email inbox

3. Expose Lambda via API Gateway

Go to API Gateway

Create an HTTP API

Integrate it with the Lambda function

Enable CORS

Deploy the API to a stage

Copy the invoke URL

4. Test Integration

Use Postman or HTML form with JavaScript fetch()

Example frontend request:

javascript
Copy
Edit
fetch("https://your-api-id.execute-api.region.amazonaws.com/contact", {
method: "POST",
body: JSON.stringify({ message: "Hello from frontend" })
})

Step 2: Deploy a Docker App Using ECS Fargate

  1. Build and Push Docker Image Dockerize your app (Flask, Node.js, etc.)

Authenticate with AWS ECR

Push the image

bash
Copy
Edit
aws ecr get-login-password | docker login ...
docker build -t my-app .
docker tag my-app:latest 123456789.dkr.ecr.region.amazonaws.com/my-app
docker push 123456789.dkr.ecr.region.amazonaws.com/my-app

2. Create ECS Cluster with Fargate

Launch a new ECS Cluster

Create a Task Definition

Choose Fargate as launch type

Assign CPU and memory

Reference your ECR image

Enable logging

3. Run the Task

Run service in public subnet

Add a Load Balancer (optional) or enable public IP

Copy the public IP or DNS to access your app

Step 3: Automate Report Processing with AWS Batch

  1. Upload Script to S3 or Include in Container
    Example script: a Python file that generates usage stats or dummy logs

  2. Setup AWS Batch Environment
    Create Compute Environment (Managed EC2 or Fargate)

Create a Job Queue

Create a Job Definition

Reference Docker image

Assign memory/CPU

Configure retry strategy and logging

3. Submit Job or Schedule with EventBridge

Manual run: Submit job in AWS Console

Automatic run: Use Amazon EventBridge rule

Frequency: Every 24 hours

Target: AWS Batch job

Conclusion

This project covered the full cycle of a serverless application—from frontend interactions to backend processing and automated scheduling. Every part was built using core AWS services and linked practically:

Component AWS Service Used
Contact Form Lambda, API Gateway, SNS
Backend App Docker, ECS Fargate
Batch Job AWS Batch, EventBridge

It is not a hypothetical tutorial—it’s a real-life project you can deploy, test, and expand. The screenshots embedded throughout this article prove that each component was successfully configured and executed.

Next Steps
Enable CloudWatch for deeper observability

Use Route 53 + ACM for HTTPS access

Add authentication with Cognito if the app grows

Top comments (0)