Follow the steps below to expose your Lambda functions as REST API endpoints in API Gateway.
For each Lambda function, you will create a Resource in API Gateway.
/session
, /index-face
).Select the correct resource from the left panel.
Click Create Method.
Select the method type (POST, GET, or DELETE).
Under Integration type, select Lambda Function.
Select your Region.
Enter the Lambda function name corresponding to the route.
Keep Timeout at 29000 ms.
Leave Authorization and other settings at default.
Click Save.
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));
Resource Path | Method(s) | Lambda Function Name |
---|---|---|
/session | GET | sessionFunction |
/liveness-result | GET (twice) | livenessResultFunction |
/index-face | POST | indexFaceFunction |
/list-collections | GET | listCollectionFunction |
/delete-face | DELETE | deleteFaceFunction |
/attendance | GET | attendanceFunction |
/liveness-result
Create this route two times:
/liveness-result
(resource)/liveness-result/{sessionId}
(resource with path parameter)
Both point to the livenessResultFunction Lambda.Repeat Step 1 and Step 2 for all routes listed in the table.
Create a new stage (example: dev
) or select an existing stage.
Click Deploy.
Copy the Invoke URL
.env
file as VITE_API_BASE_URL
.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.