I'm planning to move my lambda function configuration from environment variables to DynamoDb since my lambda functions share configurations and also I don't want to redeploy my lambda functions each time a configuration changes (my config changes frequently and once they do I have to redeploy so many lambda functions).
But in order to improve the performance of my lambda functions and also to reduce the cost, I'm not going to load the configuration per each execution. Instead, I will load the config into a global variable and since global variables persist across executions (as long as the lambda function is warmed up) I can reuse the same config without accessing DynamoDb. Here's a sample code:
let config = null;
function getConfig() {
if (config)
return Promise.resolve(config);
else {
//Load config from DynamoDb and return it in form of a promise
}
}
exports.handler = function(event, context, callback) {
getConfig()
.then(config => {
//Your code that makes use of config
})
}
So far everything is fine. Now, consider the time that DynamoDb is updated with the new configuration. The warmed-up lambda functions will continue using the old config before they are brought down by AWS and face a cold-start.
What I want to do is to signal lambda functions and force them to flush their warmed-up lambda functions and start over each time the configuration changes. I know I can redeploy them which will do exactly what I wanted. But that's what exactly I was escaping from in the first place. So, what are my options?