Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
AWS · DVA-C03

Building APIs with API Gateway

DVA-C03 · Lesson 3 of 24 · 17:41

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the DVA-C03 exam (AWS Certified Developer – Associate). In this lesson: REST, HTTP, and WebSocket APIs, proxy and non-proxy integrations, the proxy response format, mapping templates, request validation, CORS, throttling, usage plans and API keys, and the limits that shape your design. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

One API, many clients

AnyCompany Tickets exposes one API to its mobile app, its website, and a few partner ticket resellers. Each client sends slightly different requests, some send broken ones, and an old partner system only understands its own field names. This lesson covers APIs with Amazon API Gateway: the kinds of APIs, integrations, request and response transformations, and validation rules.

Three kinds of APIs

API Gateway offers three kinds of APIs. REST APIs bring the most features: API keys and usage plans, per-client throttling, request validation, mapping templates, caching, AWS WAF, and private endpoints. HTTP APIs are simpler, cost less, and support JWT authorizers, for APIs that do not need those features. And WebSocket APIs keep a two-way connection open, so the backend can push messages to clients, like a live queue position.

Integrations

The integration connects a method to its backend. With a Lambda proxy integration, API Gateway passes the whole request to the function, and returns the function's response as it is. That response must follow a fixed format: a status code, headers, and a body that is a string, or API Gateway returns a 502 Bad Gateway error. With a non-proxy integration, you control the request and the response with mapping templates, and an HTTP integration can reach any HTTP endpoint, like a partner's service.

Transforming requests and responses

In a REST API with a non-proxy integration, a mapping template transforms the payload, with a script in the Velocity Template Language. On the integration request, it can rename fields, pick values from the path, the query string, or the body, and build the format that the backend expects. On the integration response, it turns the backend's output into what clients expect, and maps backend errors to HTTP status codes. HTTP APIs have no mapping templates, but they offer parameter mapping, to change headers, query strings, and paths.

Validating requests

REST APIs can enforce validation rules before the integration runs. A request validator checks that required parameters and headers are present, and that the body matches a model, which is a JSON schema. A request that fails gets a 400 error at once, so the backend never pays for broken input. And for browser apps on another domain, the API must answer with CORS headers: with a proxy integration, the function itself must return the Access-Control-Allow-Origin header.

Protecting and shaping the API

API Gateway protects backends with throttling: too many requests get a 429 Too Many Requests error, and clients should retry with backoff. For partners, usage plans attach API keys to throttling limits and quotas, but a key identifies a client, it does not authenticate it. Keep the limits in mind: an integration has 29 seconds by default to answer, and a payload can reach 10 megabytes. Longer work belongs in an asynchronous pattern, as in lesson one.

Recap

Let's recap. REST APIs bring keys, usage plans, validation, mapping templates, and caching, HTTP APIs are simpler and cheaper, and WebSocket APIs push messages. A Lambda proxy integration needs a status code, headers, and a string body, or clients get a 502 error. Mapping templates in the Velocity Template Language transform requests and responses of non-proxy integrations. Request validators check parameters and bodies against a model, with a 400 error, and proxy functions return their own CORS headers. And throttling returns 429 errors, usage plans set quotas for API keys, and integrations answer within 29 seconds by default.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. The reseller API often receives orders with no quantity, and each one still invokes the order function, which fails. The team wants API Gateway to reject them before any code runs. What should the developer configure?

    • A Lambda authorizer that checks each body
    • A request validator with a model of the order
    • A mapping template that drops empty fields
    • A usage plan that throttles the resellers
    Show the answer

    A request validator with a model of the order

    A request validator checks the body against a model, and returns a 400 error at once, without invoking the function. “A Lambda authorizer that checks each body” would run a function for every request, and an authorizer checks who calls, not the body. “A mapping template that drops empty fields” would pass the broken order on, without a quantity. And “A usage plan that throttles the resellers” would only limit the request rate.

  2. A new function behind a Lambda proxy integration returns a dictionary with a status code and a body that is a dictionary too, and every call gets a 502 Bad Gateway error. What should the developer change?

    • The function’s timeout, raised to 29 seconds
    • The headers, with a Content-Type of JSON
    • CORS, enabled on the resource of the method
    • The body, serialized to a JSON string
    Show the answer

    The body, serialized to a JSON string

    A proxy integration needs the body as a string, so the function must serialize it to JSON, or API Gateway rejects the response. “The function’s timeout, raised to 29 seconds” would not help, because the function does not run out of time. “The headers, with a Content-Type of JSON” would only change the headers, and the body would still be a dictionary. And “CORS, enabled on the resource of the method” would add an OPTIONS method for browsers, without fixing the response.

  3. A partner’s old booking service expects XML with its own field names, while the mobile app sends JSON to the same REST API. The team wants to translate the payload without writing or running new code. What should the developer use?

    • An HTTP API with a proxy integration
    • A Lambda function that rewrites each payload
    • A mapping template on the integration request
    • A request validator with an XML model
    Show the answer

    A mapping template on the integration request

    A mapping template on the integration request rebuilds the payload in the format and with the field names that the partner expects, with no code to run. “An HTTP API with a proxy integration” would pass the JSON through unchanged. “A Lambda function that rewrites each payload” would work, but it adds a function to write, deploy, and pay for. And “A request validator with an XML model” would only check the request, without changing it.