Env variables set in serverless.yml not being built
See original GitHub issueI need to read environment variables in my lambda function. It looks like the environment variables from the serverless config are not actually set at build time when the code is transpiled - therefore undefined in the output. I have created a bash script to set them then run serverless deploy
, but is there already a solution for this?
I have the following in my function config:
environment:
MONGO_URI: ${file(${opt:secrets}):MONGO_URI}
and my webpack config for EnvironmentPlugin:
plugins: [
new webpack.EnvironmentPlugin(['NODE_ENV', 'MONGO_URI']),
],
"serverless-webpack": "^3.0.0-rc.1",
"webpack": "^3.5.6"
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Variables - Serverless Framework
Variables. Variables allow users to dynamically replace config values in serverless.yml config. They are especially useful when providing secrets for your ...
Read more >Resolution of environment variables - Serverless Framework
The framework only loads environments variables locally and does not pass them to your function's environment · The framework loads variables from only...
Read more >How to make serverless not changing the value of ...
I'm trying to add environment variable to my function in Serverless config but set value for it using Lambda console to not store...
Read more >Variables - Serverless Framework
Reference & load variables from environment variables ... Note: You can only use variables in serverless.yml property values, not property keys.
Read more >Serverless Dotenv Plugin
env variables will get resolved before this plugin is initialized. This means env variables inside serverless.yml can no longer rely on this plugin...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
👋 Just wanted to note that you forgot the lib property in your example to access the top level env object:
slsw.lib.serverless.service.provider.environment
@realseanp Oh, sorry. You’re right 👍 . Thanks for the hint.