Deploy Lambda Functions to API Gateway

Deploy Lambda Functions to API Gateway

Follow the steps below to expose your Lambda functions as REST API endpoints in API Gateway.


Step 0 – Create New API

  1. Navigate to API Gateway in the AWS Console.

alt text

  1. Select APIsREST APIBuild.

alt text

  1. Choose:
    • New API
    • Name: Example: Face Recognition API
    • Description: Optional description
  2. Click Create API.

alt text


Step 1 – Create Resources

For each Lambda function, you will create a Resource in API Gateway.

  1. Click Create Resource at the original path (/).

alt text

  1. Resource Path: Leave as generated.
  2. Resource Name: Match the route (example: /session, /index-face).
  3. Enable CORS.
  4. Click Create Resource.

alt text


Step 2 – Create Methods

  1. Select the correct resource from the left panel.
    alt text

  2. Click Create Method.

alt text

  1. Select the method type (POST, GET, or DELETE).
    alt text

  2. Under Integration type, select Lambda Function.

alt text

  1. Enable Lambda Proxy Integration.

alt text

  1. Select your Region.

  2. Enter the Lambda function name corresponding to the route.

alt text

  1. Keep Timeout at 29000 ms.

  2. Leave Authorization and other settings at default.

  3. Click Save.

alt text


Route to Lambda Mapping

import { handler as createSessionHandler } from "../../amplify/functions/sessionFunction/handler.js";
router.get("/session", lambdaToExpress(createSessionHandler));

import { handler as getSessionResultsHandler } from "../../amplify/functions/livenessResultFunction/handler.js";
router.get(
  "/liveness-result/:sessionId",
  validateSessionId,
  lambdaToExpress(getSessionResultsHandler)
);

import { handler as indexFaceHandler } from "../../amplify/functions/indexFaceFunction/handler.js";
router.post(
  "/index-face",
  upload.single("photo"),
  lambdaToExpress(indexFaceHandler)
);

import { handler as listCollectionHandler } from "../../amplify/functions/listCollectionFunction/handler.js";
router.get("/list-collections", lambdaToExpress(listCollectionHandler));

import { handler as deleteFaceHandler } from "../../amplify/functions/deleteFaceFunction/handler.js";
router.delete(
  "/delete-face",
  express.json(),
  lambdaToExpress(deleteFaceHandler)
);

import { handler as getAttendanceHandler } from "../../amplify/functions/attendanceFunction/handler.js";
router.get("/attendance", lambdaToExpress(getAttendanceHandler));

API Gateway Setup – Resource and Method Table

Resource PathMethod(s)Lambda Function Name
/sessionGETsessionFunction
/liveness-resultGET (twice)livenessResultFunction
/index-facePOSTindexFaceFunction
/list-collectionsGETlistCollectionFunction
/delete-faceDELETEdeleteFaceFunction
/attendanceGETattendanceFunction

Special Note – /liveness-result

Create this route two times:

  • /liveness-result (resource)
  • /liveness-result/{sessionId} (resource with path parameter) Both point to the livenessResultFunction Lambda.

alt text


Step 3 – Repeat for All Endpoints

Repeat Step 1 and Step 2 for all routes listed in the table.


Step 4 – Deploy API

  1. In API Gateway, click ActionsDeploy API.

alt text

  1. Create a new stage (example: dev) or select an existing stage.

  2. Click Deploy.

  3. Copy the Invoke URL

alt text

  1. Now, you can go and set the url in your frontend folder .env file as VITE_API_BASE_URL.

Example Invoke URLs

  • GET {{invoke_url}}/session
  • GET {{invoke_url}}/liveness-result/{sessionId}
  • POST {{invoke_url}}/index-face
  • GET {{invoke_url}}/list-collections
  • DELETE {{invoke_url}}/delete-face
  • GET {{invoke_url}}/attendance

And congratualtion! You have set your API Gateway up with the correct routes and Lambda functions. You can now use the API Gateway to interact, even localhost.