
Overview: what you’ll build
- A REST API named library.
- Resources: /books, /books/top (nested), and /authors.
- Lambda-backed GET methods returning simple JSON bodies.
- Demonstration of non-proxy Lambda integration and where mapping templates fit.
- Deploy to a stage (dev) and test with curl/Postman or API Gateway’s Test tool.
Create a REST API
- In the API Gateway console choose REST API → Build.
- Select Create from scratch and set the API name to “library”.
- Pick an endpoint type. Typical choices:
| Endpoint type | Use case |
|---|---|
| Regional | Default for regional traffic; no CloudFront caching |
| Edge-optimized | Better latency for global clients via CloudFront |
| Private | Accessible only from within your VPC |

Add a resource: /books
Resources in API Gateway map to URL path segments. Add a new resource named books so requests to /books route through that resource.
Create a GET method and integrate with Lambda
Add a GET method to /books. API Gateway supports standard HTTP methods (GET, POST, PUT, PATCH, DELETE, etc.). For the backend integration choose Lambda Function. Two common Lambda integration patterns:| Integration type | Description | When to use |
|---|---|---|
| Lambda Proxy Integration | API Gateway forwards the full request to Lambda. The function must return where body is a string. | Simpler to implement when you want Lambda to handle full HTTP semantics. |
| Lambda (non-proxy) Integration | API Gateway forwards only configured fields. Use mapping templates to transform request/response payloads. | Useful when you want API Gateway to control HTTP responses or transform payloads without changing Lambda code. |

Create the Lambda function: getBooks
In the Lambda console create a function named getBooks. For non-proxy integration the function can return a simple JSON object (API Gateway will map it to the HTTP response body). Example function (Node.js):When Lambda proxy integration is enabled, your handler must return where body is a string. In non-proxy mode (used here) the function can return a JSON object which you map in API Gateway.
Integration settings and method flow
Open the Method Execution view to see the visual flow: Method Request → Integration Request → Lambda function → Integration Response → Method Response → Client Integration Request controls which parts of the HTTP request (path params, query string, headers, body) are forwarded to Lambda and allows mapping templates to transform the payload. Integration Response allows you to transform Lambda output back into the final HTTP response that clients receive.

Test the method inside API Gateway
Use the built-in Test tool to simulate HTTP requests (path, query string, headers, body) and view the response and log output. Example API Gateway test output for GET /books:- Status: 200
- Latency: 112 ms
Deploy the API to a stage
To expose the API publicly you must Deploy API to a stage (e.g., dev). Stages act as environments — dev, prod, etc. Remember to redeploy after making configuration changes.Forgetting to redeploy is a common cause of “changes not taking effect.” Always deploy after configuration changes.

Add another resource: /authors
Back in the Resources view create authors and add a GET method integrated with a Lambda function named getAuthors. The Lambda can return a JSON object similar to getBooks:Create nested resources: /books/top
You can create nested resources under existing resources. Add a child resource top under /books and attach a GET method backed by a Lambda getTopBooks. Create the Lambda function getTopBooks (for example, Node.js runtime):


Quick checklist
- Create resources and methods under API Gateway → Resources (not Stages).
- Link methods to Lambda functions using proxy or non-proxy integration according to your needs.
- Use Integration Request/Response mapping templates when you need to transform payloads or control HTTP responses from API Gateway.
- Deploy to a stage and redeploy after changes.
- Test using the API Gateway Test tool, curl, or Postman.
Links and references
- API Gateway Documentation
- AWS Lambda Documentation
- OpenAPI Specification
- Postman
- curl (command-line client)