Within a lambda function, is there a way to dynamically choose an environment variable based on a passed in parameter value?
Example code below, which is not correct syntax, just for demonstration:
async function myEV (EVName) {
return {
body: process.env.{EVName},
};
}
export { myEV }
@MatJohnK It might seem like a special case, but the fact that it’s a Serverless Function and an Environment Variable is actually irrelevant.
You just use Square Bracket Notation like you always would in JavaScript to access a property via a string of its key/name.
So process.env[ EVName ]
See:
That is exactly what I needed. Many thanks @nathanmartin !