Skip to content

Instantly share code, notes, and snippets.

@maxbeatty
Created March 5, 2017 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxbeatty/573a2622d88d044c8ce2a346b5e46573 to your computer and use it in GitHub Desktop.
Save maxbeatty/573a2622d88d044c8ce2a346b5e46573 to your computer and use it in GitHub Desktop.
AWS Lambda module caching anti-pattern
var first = true;
module.exports = function () {
console.log(`first: ${first}`);
if (first) {
first = false;
}
};
const b = require('./b');
exports.handle = function handle(event, context, callback) {
var i = 0;
while (i++ < 4) {
b();
}
callback();
};
/aws/lambda/module-cache-test START RUN 1
/aws/lambda/module-cache-test 2017-03-05T18:36:51.853Z first: true
/aws/lambda/module-cache-test 2017-03-05T18:36:51.854Z first: false
/aws/lambda/module-cache-test 2017-03-05T18:36:51.854Z first: false
/aws/lambda/module-cache-test 2017-03-05T18:36:51.854Z first: false
/aws/lambda/module-cache-test END
/aws/lambda/module-cache-test START RUN 2
/aws/lambda/module-cache-test 2017-03-05T18:37:39.899Z first: false
/aws/lambda/module-cache-test 2017-03-05T18:37:39.899Z first: false
/aws/lambda/module-cache-test 2017-03-05T18:37:39.899Z first: false
/aws/lambda/module-cache-test 2017-03-05T18:37:39.899Z first: false
/aws/lambda/module-cache-test END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment