From 8cb039a32e8905709957c5272dee9f88750f9706 Mon Sep 17 00:00:00 2001 From: Dan Greaves Date: Fri, 20 Sep 2024 11:02:52 +1000 Subject: [PATCH] feat: configure lambda web adapter health check --- src/adapter/handler.ts | 8 ++++++++ src/cdk/GatsbySite.ts | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/adapter/handler.ts b/src/adapter/handler.ts index acb4f57..0632da8 100644 --- a/src/adapter/handler.ts +++ b/src/adapter/handler.ts @@ -32,6 +32,14 @@ const app = express(); // Disable X-Powered-By header. app.disable("x-powered-by"); +/** + * Endpoint used by AWS Lambda Web Adapter for readiness checks. + * @see https://github.com/awslabs/aws-lambda-web-adapter#readiness-check + */ +app.get("/__ping", (_req, res) => { + res.status(200).send("Pong"); +}); + // Register a route which listens to all requests. app.all("*", async (req, res) => { /** diff --git a/src/cdk/GatsbySite.ts b/src/cdk/GatsbySite.ts index 3f32b9c..7ba9f2f 100644 --- a/src/cdk/GatsbySite.ts +++ b/src/cdk/GatsbySite.ts @@ -209,8 +209,9 @@ export class GatsbySite extends Construct { layers: [webAdapterLayer, ...(functionOptions.layers ?? [])], environment: { ...functionOptions.environment, - // Required by web adapter. + // Configuration for AWS Lambda Web Adapter. AWS_LAMBDA_EXEC_WRAPPER: "/opt/bootstrap", + AWS_LWA_READINESS_CHECK_PATH: "/__ping", }, });