Skip to content

Commit c8bac53

Browse files
committed
add handler
1 parent 898dc96 commit c8bac53

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ import protectedRoute from "./routes/protected.js";
6060
import eventsPlugin from "./routes/events.js";
6161
/** END ROUTES */
6262

63+
export const instanceId = randomUUID();
64+
6365
const __filename = fileURLToPath(import.meta.url);
6466
const __dirname = path.dirname(__filename);
6567

src/api/lambda.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import awsLambdaFastify from "@fastify/aws-lambda";
2-
import init from "./index.js";
2+
import init, { instanceId } from "./index.js";
33
import { type APIGatewayEvent, type Context } from "aws-lambda";
44
import { InternalServerError, ValidationError } from "common/errors/index.js";
55

@@ -9,7 +9,17 @@ const realHandler = awsLambdaFastify(app, {
99
serializeLambdaArguments: true,
1010
callbackWaitsForEmptyEventLoop: false,
1111
});
12-
const handler = async (event: APIGatewayEvent, context: Context) => {
12+
type WarmerEvent = { action: "warmer" };
13+
const handler = async (
14+
event: APIGatewayEvent | WarmerEvent,
15+
context: Context,
16+
) => {
17+
if ("action" in event) {
18+
console.log(`Got warmer event for instance ID ${instanceId}.`);
19+
return {
20+
instanceId,
21+
};
22+
}
1323
if (process.env.ORIGIN_VERIFY_KEY) {
1424
// check that the request has the right header (coming from cloudfront)
1525
if (

0 commit comments

Comments
 (0)