← AWS Learning Lab

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

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.

A small synchronous request path.

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.

Connected the front end to an event-driven backend.

  1. 01
    Defined the API route

    Created a POST /contact endpoint in API Gateway as the public interface for form submissions.

  2. 02
    Implemented the Lambda handler

    Used Python to receive the API Gateway event, work with the submitted request body, and return a structured response.

  3. 03
    Configured CORS

    Allowed the website origin and the required request method and headers so the browser could call the API.

  4. 04
    Updated the contact form

    Added a JavaScript fetch request, disabled the button while sending, and surfaced the API result in the page.

The browser and API agree on the contract.

  • 01
    Valid browser submission

    Submitted the form from the website and confirmed the request reached POST /contact and returned a successful response.

  • 02
    CORS behavior

    Verified the browser was permitted to send the cross-origin JSON request rather than blocking it before Lambda ran.

  • 03
    Front-end states

    Checked required-field validation, the sending state, the returned message, form reset, and visible error feedback.

An API is a contract across several boundaries.

  • 01
    The 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.

  • 02
    CORS is explicit access control.

    It is a browser-enforced agreement about which origin, methods, and headers may use the API.

  • 03
    Serverless still needs clear responsibilities.

    API Gateway owns the HTTP boundary while Lambda owns application logic. Keeping that distinction clear made troubleshooting easier.