Lab 02
Serverless API
A browser-to-Lambda request path that turns the static contact form into a working API client.
API Gateway · Lambda · Python · CORS
Lab milestone complete
Problem
A static form cannot process its own submission.
The website could collect a name, email address, and message in the browser, but it needed a backend endpoint to receive that data and return a useful response.
The goal was to add that backend capability without introducing a continuously running server or changing the site’s static deployment model.
Architecture
A small synchronous request path.
Contact request
API Gateway provides the public HTTP interface; Lambda runs the request-handling code only when invoked.
The website sends JSON to POST /contact. API Gateway passes the request to the Python Lambda handler, and the handler returns an HTTP response that the page uses to show success or failure feedback.
Build
Connected the front end to an event-driven backend.
- 01Defined the API route
Created a
POST /contactendpoint in API Gateway as the public interface for form submissions. - 02Implemented the Lambda handler
Used Python to receive the API Gateway event, work with the submitted request body, and return a structured response.
- 03Configured CORS
Allowed the website origin and the required request method and headers so the browser could call the API.
- 04Updated the contact form
Added a JavaScript
fetchrequest, disabled the button while sending, and surfaced the API result in the page.
What I Tested
The browser and API agree on the contract.
- 01Valid browser submission
Submitted the form from the website and confirmed the request reached
POST /contactand returned a successful response. - 02CORS behavior
Verified the browser was permitted to send the cross-origin JSON request rather than blocking it before Lambda ran.
- 03Front-end states
Checked required-field validation, the sending state, the returned message, form reset, and visible error feedback.
What I Learned
An API is a contract across several boundaries.
- 01The browser is part of the system.
A working Lambda is not enough; request shape, response shape, status codes, and front-end states all have to align.
- 02CORS is explicit access control.
It is a browser-enforced agreement about which origin, methods, and headers may use the API.
- 03Serverless still needs clear responsibilities.
API Gateway owns the HTTP boundary while Lambda owns application logic. Keeping that distinction clear made troubleshooting easier.