Even though the dashboard for the Lambda function shows me NODE_ENV
listed as an environment variable, process.env.NODE_ENV
is undefined when I run my Node AWS Lambda function.
This code...
console.log('node process env NODE_ENV:');
console.log(process.env.NODE_ENV);
logs this:
node process env NODE_ENV:
undefined
I was wondering if it was a role issue, so I gave its role all permissions on AWS Lambda, but it didn't help.
For what it's worth, I'm using Claudia bot builder, running the npm script
"deploy:production": "claudia update --version production --set-env NODE_ENV=production",
But like I say, the NODE_ENV
environment shows in the list of environment variables in the dashboard for the function.
Any ideas?
Turns out the problem was that Webpack compressed away process.env
.
I got around the issue by using babel-plugin-transform-inline-environment-variables, which inlines the environment variables at build-time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With