Skip to main content
In this walkthrough you’ll build a minimal “cars” inventory API using Amazon API Gateway (REST API) to route HTTP requests to AWS Lambda functions. The example demonstrates how to:
  • Create a REST API and resources (paths)
  • Add methods (GET, POST, PATCH/PUT, DELETE)
  • Integrate methods with Lambda functions (using Lambda proxy integration)
  • Deploy and invoke the API
Search for API Gateway in the AWS Console and open the API Gateway service page. Choose the API type you want to create.
Screenshot of the AWS API Gateway console's "Choose an API type" page, showing options for HTTP API, WebSocket API, and REST API with accompanying descriptions and Build/Import buttons. The browser header shows the AWS navigation bar and region.
Create a REST API. Select Build → New API, give it a name (for example, cars), choose the endpoint type (Regional), and click Create API.
A screenshot of the AWS API Gateway "Create REST API" page showing options to create/import/clone/example APIs, with "New API" selected and the API name field filled as "cars." The Regional endpoint type and a "Create API" button are visible at the bottom.
Create the /cars resource — this will be the base path clients call. You can enable CORS here if your clients require cross-origin access; for this demo it’s left unchecked. Click Create Resource.
A screenshot of the AWS API Gateway console showing the Resources view for an API named "cars" with the /cars resource selected. The resource details show path "/cars", no methods defined, and a green banner saying "Successfully created resource '/cars'."
We’ll route requests on /cars to Lambda functions. First, review the read-only Lambda that returns a static list of cars.
A screenshot of the AWS Lambda console showing the "Get-cars" function overview, including its ARN, last modified time, and a code source section. The page also shows options like Add destination, Layers, and tabs for Code, Test, Monitor, Configuration, Aliases, and Versions.
Example handler for the get-cars Lambda (returns a fixed list):
Create a GET method on the /cars resource and integrate it with the Get-cars Lambda function. When creating the integration, enable Lambda proxy integration (recommended) so the Lambda receives the full request event (headers, pathParameters, queryStringParameters, body, etc.). The API Gateway console usually adds the necessary invoke permission on the Lambda automatically. If you configure integrations manually or with Infrastructure as Code, remember to grant API Gateway permission to invoke the function (lambda:AddPermission).
A screenshot of the AWS API Gateway console showing the Resources view for an API named "cars" with a GET method configured and integrated with a Lambda function. A green banner at the top indicates the GET method was successfully created.
Any time you change methods or integrations you must deploy the API for the changes to take effect. Deploy the API to a stage (for example, development) via Deploy API and add an optional description.
A screenshot of the AWS API Gateway console with a "Deploy API" dialog asking to select a stage and enter a deployment description. The background shows the API Resources view and Lambda integration details.
After deployment, open the stage and copy the Invoke URL. Note: calling the API root (no resource path) will return “Missing Authentication Token” because the root has no methods defined. Example base invoke URL: https://q2ns69dn0b.execute-api.us-east-1.amazonaws.com/development To call the GET method for our cars list: https://q2ns69dn0b.execute-api.us-east-1.amazonaws.com/development/cars When using Lambda proxy integration, API Gateway builds the HTTP response from the Lambda’s return object. For the get-cars handler above, the Lambda returns:
API Gateway will forward the contents of body as the HTTP response body to the client (clients should parse that JSON). Next, add the remaining CRUD endpoints. This demo includes Lambda functions: create-car, update-cars, and delete-car.
A screenshot of the AWS Lambda console showing a list of four functions (update-cars, create-car, Get-cars, delete-car). Each function is packaged as a Zip and uses the Node.js 18.x runtime.
Create a POST method on /cars and integrate it with the create-car Lambda. After adding the method, deploy the API again.
A screenshot of the AWS API Gateway console showing the Resources page for an API named "cars," with a /cars POST method configured and integrated with a Lambda function. A green banner at the top indicates the POST method was successfully created.
Example POST request body (JSON):
A simple create-car Lambda that echoes the created car and returns a 201:
If your Lambda code calls JSON.parse(event.body) and you get a SyntaxError complaining about “Unexpected token u”, that usually means event.body is undefined. This typically happens when API Gateway is not passing the request body—enable Lambda proxy integration and redeploy the API so the full request event is forwarded to your function.
If you encounter this error:
enable Lambda proxy integration, redeploy the API, and retry your POST. With proxy integration enabled the Lambda receives an event object containing body, headers, pathParameters, queryStringParameters, etc. A successful response for the POST above might be: Request body:
Response body:
For updates, use a path parameter to identify the resource. Under /cars create a new resource named {id} (enter {id} into the console resource name). This creates a variable path segment accessible in Lambda as event.pathParameters.id.
A screenshot of the AWS API Gateway console showing the "Create resource" page for a /cars/ resource with the resource name set to {id}. A green banner at the top says a deployment for "cars" was successfully created.
Under /cars/{id} create a PATCH (or PUT) method and integrate it with the update-cars Lambda. Enable proxy integration so body and pathParameters are forwarded. Deploy the API after creating the method. Example update-cars handler:
When testing PATCH https://q2ns69dn0b.execute-api.us-east-1.amazonaws.com/development/cars/5 with a JSON body you can also log or return the entire event to see what API Gateway supplies. A typical event includes keys such as resource, path, httpMethod, headers, pathParameters, queryStringParameters, body, and requestContext. Example event (abridged):
Finally, support deletion by adding a DELETE method on /cars/{id} and integrating it with the delete-car Lambda. The console panel to create the DELETE method and choose Lambda integration is shown below.
A screenshot of the AWS API Gateway "Create method" console showing the Method type set to DELETE. The Integration type panel is visible with "Lambda function" selected and other options like HTTP, Mock, AWS service, and VPC link.
When the API is no longer needed you can delete it in the API Gateway console (select the API → Delete → Confirm). Summary checklist
  • Create an API and define resources (for example, /cars and /cars/{id})
  • Add methods (GET/POST/PATCH/DELETE) and set Lambda integration
  • Prefer Lambda proxy integration to receive the full event (body, pathParameters, headers, etc.)
  • Deploy the API to a stage after each change
  • Test GET in a browser, and use curl/Postman for POST, PATCH, DELETE
Endpoints and example usage Links and references
If you configure integrations via IaC or the CLI, remember to add the Lambda permission that allows API Gateway to invoke the function. Without it you’ll receive 500/403 errors when the method is invoked.

Watch Video