Skip to content

Instantly share code, notes, and snippets.

@JoeStanton
Last active January 17, 2017 14:24
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 JoeStanton/f57b25736798fc011e95807ed5dfed1a to your computer and use it in GitHub Desktop.
Save JoeStanton/f57b25736798fc011e95807ed5dfed1a to your computer and use it in GitHub Desktop.
Lambda container lifetime
var startedAt = (new Date).toString();
var lastExecuted = null;
exports.ping = function(event, context, done) {
lastExecutedCopy = lastExecuted;
lastExecuted = (new Date).toString();
done(null, {
warm: !!lastExecutedCopy,
startedAt: startedAt,
last: lastExecutedCopy,
now: lastExecuted
});
};
require 'json'
def test(interval, desc)
before = JSON.parse(`sls invoke -f ping`)
sleep interval
after = JSON.parse(`sls invoke -f ping`)
outcome = after["warm"] ? "warm" : "cold"
puts "Function was #{outcome} after #{desc}"
end
test(15 * 60, "fifteen minutes")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment