Keep your Lambdas warm!
This repository contains a Terraform module that can be imported into any Terraform file/project.
It will keep your Lambda functions warm at the specified concurrency and rate setting.
A quick three-step installation process with examples (for Node.js, Python, and Java) to get you rolling, fast.
Three-step installation process.
-
Add the module configuration to your Terraform file.
module "fireplace" { source = "github.com/khalidx/fireplace.git?ref=master" functions = [ ] }
-
Make sure your code can detect and handle a warming event (it should sleep for 75 milliseconds).
Example: Node.js
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); export const handler = async (event, context) => { if (event.type = "LambdaWarmerEvent") { await delay(75); return; } ...regular handler logic here... }
Example: Python
Example: Java
-
Initialize Terraform to install the module, and deploy! Your functions will stay nice and warm.
terraform init terraform apply
This section is for developers interested in modifying or extending this project.
The following commands are made available for your convenience when developing the code in this repository.
Runs the tests defined in the src/index.test.ts
file.
Ensure you have valid credentials set as environment variables when running tests locally. Basically, the AWS_REGION
and AWS_PROFILE
environment variables should be set. Click here for more information about the various options for setting AWS credentials.
npm run test
Builds the TypeScript code and outputs a JavaScript file to dist/bundle.js
, then zips the dist/
directory.
npm run build
Deploys (applies) the example that leverages this module, using Terraform.
npm run deploy-example
Undeploys (destroys) the example that leverages this module, using Terraform.
npm run undeploy-example
Please open a GitHub issue for a quick response to your question, comment, concern, or suggestion.
Thanks for reading!
Also, a big thanks to Jeremy Daly and others for writing great posts about the "intricacies" of warming AWS Lambda Functions.