Skip to content

Latest commit

 

History

History
123 lines (78 loc) · 2.93 KB

README.md

File metadata and controls

123 lines (78 loc) · 2.93 KB

fireplace

Keep your Lambdas warm!

Introduction

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.

Usage

Three-step installation process.

  1. Add the module configuration to your Terraform file.

    module "fireplace" {
      source       = "github.com/khalidx/fireplace.git?ref=master"
      functions    = [
        
      ]
    }
  2. 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

  3. Initialize Terraform to install the module, and deploy! Your functions will stay nice and warm.

    terraform init
    terraform apply

Developers

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.

test

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

build

Builds the TypeScript code and outputs a JavaScript file to dist/bundle.js, then zips the dist/ directory.

npm run build

deploy-example

Deploys (applies) the example that leverages this module, using Terraform.

npm run deploy-example

undeploy-example

Undeploys (destroys) the example that leverages this module, using Terraform.

npm run undeploy-example

Support

Please open a GitHub issue for a quick response to your question, comment, concern, or suggestion.

Thanks

Thanks for reading!

Also, a big thanks to Jeremy Daly and others for writing great posts about the "intricacies" of warming AWS Lambda Functions.