@ixor/aws-cdk-lambda-warmer
v0.1.0
Published
## Description
Downloads
2
Keywords
Readme
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 warmcount
times with a dummy event containing 2 propertiesdummy
anddummySleepSeconds
- 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 installedaws-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
- https://www.npmjs.com/package/@ixor/aws-cdk-ixor-lambda