AWS Lambda functions cannot be configured with environment variables, but quite often your function need to behave differently in staging and production environments.
In a such case, put your environment-specific variables into separate configs and resolve the config based on the context.functionVersion value. Apination connector functions have 2 aliases which point to different versions. It’s also recommended to pass context.functionVersion=TEST during tests, to have a config for running tests.
Node.js Sample
exports.handler = function(event, context) {
if(!context.functionVersion) throw new TypeError('context.functionVersion argument required');
const environment =
context.functionVersion === 'TEST' ? 'test' :
context.functionVersion === '$LATEST' ? 'staging' :
'production';
const config = require(`./config/${environment}.json`);
// TODO: use environment-specific variables defined in config
}