Created
January 17, 2022 04:32
-
-
Save usausa/4796fa0db87edf31d3edfa276f91014f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const aws = require('aws-sdk'); | |
const lambda = new aws.Lambda({ | |
maxRetries: 10, | |
retryDelayOptions: { | |
base: 1000 | |
} | |
}); | |
const targets = process.env.TARGETS.split(','); | |
const warmer = process.env.AWS_LAMBDA_FUNCTION_NAME; | |
exports.handler = async () => { | |
let result = await lambda.listFunctions().promise(); | |
let functions = []; | |
while (true) { | |
functions = functions.concat( | |
result.Functions | |
.filter(f => targets.some(x => f.FunctionName.startsWith(x)) && (f.FunctionName !== warmer)) | |
.map(f => lambda.invoke({ FunctionName: f.FunctionName, InvocationType: 'RequestResponse', Payload: JSON.stringify({ headers: { 'X-Lambda-Hot-Load': 'true' } }) }).promise())); | |
if (!result.nextmarker) { | |
break; | |
} | |
result = await lambda.listFunctions({ Marker: result.nextmarker }).promise(); | |
}; | |
await Promise.all(functions); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Warming AWS Lambda.