Skip to content

Latest commit

 

History

History
50 lines (33 loc) · 1.51 KB

File metadata and controls

50 lines (33 loc) · 1.51 KB

Lambda Keep Active

View on Construct Hub

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.

Installation

npm i @beesolve/lambda-keep-active

Quick Start

import { LambdaKeepActive } from "@beesolve/lambda-keep-active";

const warmer = new LambdaKeepActive(this, "KeepAliveLambda");

const handler = new NodejsFunction(this, "Handler", { /** your props */ });

warmer.keepActive(handler);

Handler Wrappers

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();
  }),
};