This is the architecture behind the contact form on this site. We use it as our own first case study: it is small, it is real, and it is the same pattern we build for clients who need a form that works.
The problem
A contact form has one job, and it fails quietly. A message gets lost, or the notification lands in spam, and nobody finds out until a customer asks why nobody replied. The design below is built around never losing a message and never failing silently.
How it works
- The browser posts the form to
/api/contact, served through CloudFront. - API Gateway passes the request to a Lambda function.
- The function checks the input and ignores any submission where the hidden honeypot field is filled in.
- It saves the submission to DynamoDB first.
- It then sends a plain-text email through SES, with the visitor’s address as the reply-to.
- It returns a short success response, and the page shows the “FILED” stamp.
Decision log
| Decision | Why |
|---|---|
| Save to DynamoDB before sending email | If email fails, the message still exists and can be recovered. |
| Plain-text email only | No markup from visitors ends up rendered in our inbox. |
| Honeypot field only, WAF left out | The honeypot costs nothing. WAF CAPTCHA adds a monthly fee and can be added later if spam shows up. |
| No third-party form service | The data stays in our AWS account and the pieces are ones we already run. |
| Return success if the email fails but the save worked | The visitor did nothing wrong. We get the alarm, not them. |
Keeping watch
- A CloudWatch alarm fires if the function logs an error or an email fails.
- A Synthetics canary loads the home page and posts a flagged test message to the form API every 15 minutes, so a broken path is found by us, not by a customer.
- Alarms notify us through SNS.
Things to do before launch
- Move SES out of sandbox mode, and set up SPF, DKIM and DMARC for the domain.
- Back up the DynamoDB table.
- Confirm the address that receives the notification.