question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Env variables set in serverless.yml not being built

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
pizzarobcommented, Oct 1, 2017

👋 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

0reactions
HyperBraincommented, Oct 2, 2017

@realseanp Oh, sorry. You’re right 👍 . Thanks for the hint.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found