Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda Environment Variables not set, process.env undefined in Node

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?

like image 256
Mikal Madsen Avatar asked May 04 '17 15:05

Mikal Madsen


1 Answers

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.

like image 68
Mikal Madsen Avatar answered Oct 13 '22 23:10

Mikal Madsen