Intermediate 25 min

What We’re Building

A simple Notes API. It stores notes in memory (we’ll add a database later if you want).

API Endpoints

GET /health

  • Purpose: Check if the API is working
  • Response: { "status": "ok", "timestamp": "2025-12-02T10:00:00Z" }

GET /notes

  • Purpose: Get all notes
  • Response: { "notes": [{ "id": 1, "text": "Buy milk" }, { "id": 2, "text": "Call mom" }] }

POST /notes (optional bonus)

  • Purpose: Add a new note
  • Request body: { "text": "New note" }
  • Response: { "id": 3, "text": "New note" }

That’s it. Simple and focused.

Request/Response Lifecycle

Here’s what happens when someone calls your API:

HTTP Request Event Invoke Return Response HTTP Response Client API Gateway Lambda Function Your Code Response

Step-by-Step Flow

  1. Client sends HTTP request - Someone calls GET https://your-api.execute-api.us-east-1.amazonaws.com/prod/notes

  2. API Gateway receives it - AWS API Gateway is like a doorman. It receives HTTP requests and routes them.

  3. API Gateway invokes Lambda - Gateway converts the HTTP request into an event and calls your Lambda function.

  4. Lambda runs your code - Your function receives the event, processes it, and returns a response.

  5. Response flows back - Lambda → API Gateway → Client

  6. Client gets response - The user sees the JSON response.

Understanding Statelessness

Each request is independent. Your code doesn’t remember previous requests.

Why this matters:

  • Lambda functions can run on different machines
  • No shared memory between requests
  • Each request is self-contained

What this means for our API:

  • We’ll store notes in memory (they’ll be lost when Lambda stops)
  • For production, you’d use a database (DynamoDB, RDS, etc.)
  • For this tutorial, in-memory is fine

Architecture Diagram

Here’s the complete picture:

Internet

   │ HTTP Request

API Gateway (AWS)

   │ Event

Lambda Function (AWS)

   │ Executes

Your Code (Node.js)

   │ Returns JSON

Lambda Function

   │ Response

API Gateway

   │ HTTP Response

Internet

Optional (for later):

Lambda Function

   │ Query/Write

Database (DynamoDB/RDS)

We won’t add a database in this tutorial, but you can add one later.

What Each Component Does

API Gateway

Role: HTTP endpoint manager

What it does:

  • Receives HTTP requests
  • Routes to Lambda functions
  • Handles authentication (if you add it)
  • Provides the public URL
  • Manages CORS, rate limiting, etc.

You configure: Routes (like /notes → Lambda function)

Lambda Function

Role: Code executor

What it does:

  • Runs your code when called
  • Provides runtime (Node.js, Python, etc.)
  • Manages scaling automatically
  • Handles timeouts and errors

You provide: The code

Your Code

Role: Business logic

What it does:

  • Processes requests
  • Returns responses
  • Can call other services (databases, APIs, etc.)

You write: Everything

Key Takeaways

Before we start coding:

  1. Three endpoints: /health, /notes (GET), /notes (POST)
  2. Request flow: Client → API Gateway → Lambda → Your Code → Response
  3. Stateless: Each request is independent
  4. Simple storage: In-memory for now (database later)

What’s Next?

In the next page, we’ll build the API locally first. This lets us test it before deploying to AWS.