teluzia.Cloud Engineer · Day 65
CHAPTER 10 · SERVERLESS AND MESSAGING

API Gateway

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

API Gateway is a reception desk: routes direct requests, authorization checks the visitor, and integrations pass accepted work to a backend. An API separates its public request contract from backend implementation. A route identifies an HTTP method and path; an integration tells API Gateway where to send matching traffic. HTTP APIs and REST APIs differ in features, so choosing one requires checking authorization, transformation, deployment, and operational requirements first. Authentication establishes identity; authorization decides whether that identity may perform the operation. CORS tells browsers whether cross-origin JavaScript may read a response; it is not an access-control substitute. APIs also need input validation and deliberate handling of public versus protected routes, regardless of what a browser allows.

Think of it this way

API Gateway is a reception desk: routes direct requests, authorization checks the visitor, and integrations pass accepted work to a backend.

TOPIC 01 / 03Step by step

Routes and integrations

An API separates its public request contract from backend implementation. A route identifies an HTTP method and path; an integration tells API Gateway where to send matching traffic. HTTP APIs and REST APIs differ in features, so choosing one requires checking authorization, transformation, deployment, and operational requirements first. For example, gET /health can integrate with a Lambda handler; POST /orders is a different route even if both use the same function.

WORKED EXAMPLE
GET /health can integrate with a Lambda handler; POST /orders is a different route even if both use the same function.

Follow a mobile application's request to GET /products/42. The client resolves the API hostname and establishes TLS. API Gateway matches the HTTP method and configured route, then sends an integration request to the chosen backend. The backend receives the integration's event format rather than an arbitrary copy of the client's network connection. Its response must satisfy the selected integration contract before Gateway returns a client response.

A route is the method/path rule that selects handling. An integration is the connection from that rule to the backend. A stage is a deployment context with behavior depending on the API type. Changing a handler without deploying the relevant API configuration can leave clients using older route settings. REST APIs and HTTP APIs have different feature sets and payload conventions. Choose from required features, then read the exact API type's documentation; combining examples from both types often creates a valid-looking configuration with the wrong request or response shape.

Why this matters

A precise route table makes client behavior predictable and prevents backend changes from accidentally creating undocumented interfaces that callers learn to depend on.

A common trap

Mixing instructions for REST APIs and HTTP APIs produces incorrect console steps or event parsing because their integration and payload details can differ.

MAKE IT VISIBLE

Follow a request through the system

FOLLOW THE SIGNAL

What happens after you press Enter?

Explore a common HTTPS request path. Select a stage, then inject a simulated failure to see what you would investigate.

STAGE 1

Find the destination

The browser resolves a hostname to an address using DNS. A cached answer may avoid a new lookup. If resolution fails, the request never reaches the server.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Routes and integrations

An API separates its public request contract from backend implementation. A route identifies an HTTP method and path; an integration tells API Gateway where to send matching traffic. HTTP APIs and REST APIs differ in features, so choosing one requires checking authorization, transformation, deployment, and operational requirements first. For example, gET /health can integrate with a Lambda handler; POST /orders is a different route even if both use the same function.

WORKED EXAMPLE
GET /health can integrate with a Lambda handler; POST /orders is a different route even if both use the same function.

Follow a mobile application's request to GET /products/42. The client resolves the API hostname and establishes TLS. API Gateway matches the HTTP method and configured route, then sends an integration request to the chosen backend. The backend receives the integration's event format rather than an arbitrary copy of the client's network connection. Its response must satisfy the selected integration contract before Gateway returns a client response.

A route is the method/path rule that selects handling. An integration is the connection from that rule to the backend. A stage is a deployment context with behavior depending on the API type. Changing a handler without deploying the relevant API configuration can leave clients using older route settings. REST APIs and HTTP APIs have different feature sets and payload conventions. Choose from required features, then read the exact API type's documentation; combining examples from both types often creates a valid-looking configuration with the wrong request or response shape.

Why this matters

A precise route table makes client behavior predictable and prevents backend changes from accidentally creating undocumented interfaces that callers learn to depend on.

A common trap

Mixing instructions for REST APIs and HTTP APIs produces incorrect console steps or event parsing because their integration and payload details can differ.

Authentication, authorization, and CORS

Authentication establishes identity; authorization decides whether that identity may perform the operation. CORS tells browsers whether cross-origin JavaScript may read a response; it is not an access-control substitute. APIs also need input validation and deliberate handling of public versus protected routes, regardless of what a browser allows. For example, allow a frontend origin to call GET /health, while requiring an authorizer for POST /orders; nonbrowser clients still need authorization.

WORKED EXAMPLE
Allow a frontend origin to call GET /health, while requiring an authorizer for POST /orders; nonbrowser clients still need authorization.

Consider a browser frontend on shop.example making a request to api.example. Before some cross-origin requests, the browser sends an OPTIONS preflight asking whether the origin, method, and headers are allowed. A successful CORS configuration permits the browser to expose the later response to frontend JavaScript. It does not establish the user's identity or grant access to a protected order.

Authentication answers who is calling. Authorization answers what that caller may do. CORS is a browser policy for reading cross-origin responses. A command-line client does not rely on the browser's CORS enforcement. Therefore, protect POST /payments with the appropriate authorizer even when only one frontend origin is allowed. When debugging, distinguish an OPTIONS failure, an invalid token, and a backend validation error. Allowing every origin may make a development symptom disappear while leaving the real authorization problem unchanged, and credentialed browser requests need additional deliberate configuration.

Why this matters

These controls solve different problems, so separating them avoids exposing protected data while debugging browser errors or choosing convenient development origins temporarily.

A common trap

Setting Access-Control-Allow-Origin to a permissive value does not protect an endpoint; an unauthenticated command-line client can still send requests directly.

HTTP status, throttling, and observability

Response status communicates the class of outcome: success, client error, or server error. Throttling limits request rates and may reject bursts. Access logs and backend logs answer different questions, so correlate them using request identifiers. Configure log retention and avoid recording authorization headers or sensitive request bodies. For example, a malformed order receives 400; an unexpected backend failure receives 500; request ID r-17 connects gateway timing with handler logs.

WORKED EXAMPLE
A malformed order receives 400; an unexpected backend failure receives 500; request ID r-17 connects gateway timing with handler logs.

A client sends fifty requests in a burst. Gateway can reject some requests before the handler runs, while another request reaches the backend and fails during a dependency call. Both failures may appear as an unsuccessful screen, but their diagnostic evidence and retry choices differ. Inspect the gateway status, integration status where available, latency, and request identifier before editing code.

Throttling limits accepted traffic according to configured rate and burst behavior. A request identifier correlates logs for one attempt. A status code communicates the response category, not a complete explanation. Clients may retry a 429 or selected transient failures with exponential backoff and jitter, but should not indefinitely repeat malformed 400 requests. A retry of a write operation also needs duplicate protection. Access logging helps explain which boundary rejected traffic, yet logging complete request bodies or authorization headers can expose private data. Record useful metadata and choose retention intentionally rather than collecting everything permanently.

Why this matters

Consistent status codes and correlated timing help distinguish client mistakes, gateway rejection, and backend faults before unnecessary infrastructure changes complicate the incident.

A common trap

Returning HTTP 200 for every error makes automated clients believe failed operations succeeded and prevents meaningful dashboards or retry decisions downstream.

KEEP THESE WITH YOU

Today’s takeaways

Routes and integrations: An API separates its public request contract from backend implementation. A route identifies an HTTP method and path; an integration tells API Gateway where to send matching traffic. HTTP APIs and REST APIs differ in features, so choosing one requires checking authorization, transformation, deployment, and operational requirements first.

Authentication, authorization, and CORS: Authentication establishes identity; authorization decides whether that identity may perform the operation. CORS tells browsers whether cross-origin JavaScript may read a response; it is not an access-control substitute. APIs also need input validation and deliberate handling of public versus protected routes, regardless of what a browser allows.

HTTP status, throttling, and observability: Response status communicates the class of outcome: success, client error, or server error. Throttling limits request rates and may reject bursts. Access logs and backend logs answer different questions, so correlate them using request identifiers. Configure log retention and avoid recording authorization headers or sensitive request bodies.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed