A CDK construct that periodically invokes your Lambda functions to prevent them from transitioning to the inactive state.
Lambda functions become inactive after approximately 14 days of idleness. Waking an inactive function can take up to 90 seconds. This construct invokes your functions every 3 days to keep them active.
npm i @beesolve/lambda-keep-activeimport { LambdaKeepActive } from "@beesolve/lambda-keep-active";
const warmer = new LambdaKeepActive(this, "KeepAliveLambda");
const handler = new NodejsFunction(this, "Handler", { /** your props */ });
warmer.keepActive(handler);Use the keptActive wrapper in your Node.js Lambda handlers to short-circuit keep-alive invocations:
import { keptActive } from "@beesolve/lambda-keep-active/runtime";
export const handler = keptActive(async () => {
// your handler code
});For Bun Lambda handlers, use keptActiveFetch:
import { keptActiveFetch } from "@beesolve/lambda-keep-active/runtime";
export default {
fetch: keptActiveFetch(async (request: Request): Promise<Response> => {
// your handler code
return new Response();
}),
};