@ixor/aws-cdk-lambda-warmer

0.1.0 • Public • Published

Lambda Warmer Lambda: Keep your Lambda's warm

Description

This repo contains a AWS CDK stack that can be deployed to any AWS account. The stack contains a single Lambda and IAM permissions to allow CloudWatch Events to invoke the function, and the function to invoke all Lambda's in the account/region where the stack is deployed.

You should, preferably in an automated way, create a AWS CloudWatch event for every function you want to be warm. The event to sent to the KeepWarm lambda looks like this:

{
  "lambdaArn": "arn:aws:lambda:eu-central-1:123456789012:function:functionToKeepWarm",
  "count": 5
}

When the KeepWarm function is invoked by the CloudWatch Rule, this wil happen:

  • the event is read and interpreted
  • the KeepWarm function asynchronously invokes the Lambda to be kept warm count times with a dummy event containing 2 properties dummy and dummySleepSeconds
  • the target Lambda will interpret the dummy event, and will sleep for the requested amount of seconds
  • without the sleep, the target Lambda might have already finished before the next invoke by the KeepWarm lambda, resulting in less than desired warm lambda's

Deploying this AWS CDK stack

To deploy the KeepWarm Lambda on a AWS account:

  • set credentials with sufficient permissions
  • make sure all requirements are met
    • aws-cdk is installed
    • aws-cli is installed
  • run this command:
cdk deploy

How to change your Lambda to correctly process the dummy event

  • Check for the dummy property in the incoming event
  • Sleep for dummySleepSeconds seconds (default to 1)
  • Return immediately after the sleep

Links and Resources

Readme

Keywords

Package Sidebar

Install

npm i @ixor/aws-cdk-lambda-warmer

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

18.9 kB

Total Files

16

Last publish

Collaborators

  • ddewaele
  • ixorci
  • jancaals
  • rtytgat
  • wvanlaer
  • jefceuppens
  • kato_duwee
  • jvanhent