Skip to content

Instantly share code, notes, and snippets.

@Jonathan-Mckenzie
Last active June 5, 2021 16:20
Show Gist options
  • Save Jonathan-Mckenzie/e706a57af2d7b586071ef7c789fd676f to your computer and use it in GitHub Desktop.
Save Jonathan-Mckenzie/e706a57af2d7b586071ef7c789fd676f to your computer and use it in GitHub Desktop.
Lambda Warmer... by using a Lambda (node.js)
/*
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