Last active
June 5, 2021 16:20
-
-
Save Jonathan-Mckenzie/e706a57af2d7b586071ef7c789fd676f to your computer and use it in GitHub Desktop.
Lambda Warmer... by using a Lambda (node.js)
This file contains 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
/* | |
Setup a cloudwatch trigger to call this at an interval slightly less than AWS's timeout for making your lambdas cold. | |
*/ | |
const https = require('https'); | |
// add new lambda endpoints here | |
const lambdaHttpEndpoints = [ | |
// add endpoints here | |
// e.g. "http://example.com", | |
]; | |
exports.handler = async (event) => { | |
for (const endpoint of lambdaHttpEndpoints) { | |
await new Promise((resolve, reject) => { | |
const req = https.get(endpoint, function(res) { | |
console.log(`${endpoint} response: `, res.statusCode); | |
resolve(); | |
}); | |
}); | |
} | |
const response = { | |
statusCode: 200, | |
body: 'lambdas are hot', | |
}; | |
return response; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment