Serverless
Building a Contact API with API Gateway + Lambda + DynamoDB
A walkthrough of how a contact form is saved through a serverless API, from frontend submission to DynamoDB storage.
Even a static site needs a place to store user input such as contact form submissions. On this site, the contact API is built with API Gateway + Lambda + DynamoDB.
Summary
The frontend calls POST /contact. API Gateway invokes Lambda. Lambda validates the input and saves it to DynamoDB.
End-to-end flow
- The user fills in the contact form.
- The frontend checks required fields and email format.
- The frontend sends a JSON request to
POST /contacton API Gateway. - Lambda parses the request body.
- Lambda checks the honeypot field.
- Lambda runs its own validation.
- Lambda calls
PutItemon DynamoDB. - Lambda returns a success response.
- The frontend shows a completion message.
Why not validate only on the frontend?
Frontend checks exist to improve user experience. They cannot be trusted from a security point of view.
Anyone can call the API directly, so Lambda also checks required fields, length limits, email format, and the honeypot.
Data saved to DynamoDB
The stored items include contactId, createdAt, name, email, subject, message, sourcePage, status, and userAgent.
CloudWatch Logs do not contain the full email address or full message body. Logs only keep the minimum information needed for troubleshooting, such as requestId, contactId, and the error type.
CORS handling
In production, the allowed origin is limited to the production domain. localhost is allowed only during development.
Avoid running production with CORS set to *.
Benefits of this setup
- No EC2 to manage.
- No server administration.
- Low cost for low-traffic workloads.
- Uses the core AWS services covered in AWS certification exams.
- Easy to explain the design intent in a portfolio.
Related terms
Read next
What to learn next
Combine blog posts with the AWS glossary, service comparisons, practice questions, and architecture gallery to connect exam knowledge with implementation.