serverless-mocha-plugin icon indicating copy to clipboard operation
serverless-mocha-plugin copied to clipboard

Environment variables are not available

Open frankTurtle opened this issue 6 years ago • 6 comments

  • Testing lambda function
  • trying to call process.env.variableName
  • getting undefined
  • printed out environment variables, they're not in the list
  • environment variables are accessible in regular serverless mocha tests, just not lambda functions.

frankTurtle avatar Apr 12 '18 21:04 frankTurtle

Just ran into this myself. Are there any workarounds?

jplock avatar May 15 '18 18:05 jplock

I am facing the same issue. Getting undefined for environment variables

hazrul avatar May 23 '18 06:05 hazrul

I know this issue is a bit old, but I'm too facing it, but only for a specific use case. Basically, any environment variable defined in the "provider" can be retrieved properly using "process.env":

But any environment variable defined at a function level cannot.

provider
  environment:
    FOO: foo <-- I can get it in my tests with process.env
functions:
  MyFunction:
    environment:
      BAR: bar <-- I cannot

For now I duplicate this function's env. variables in a dedicated json file, but being able to not duplicate them (and risk out-of-sync issue) would be great.

Thana404 avatar Dec 28 '18 10:12 Thana404

I'm having this same issue with cf variables being not populated on sls version: 1.51.0.

// variable in serverless.yaml
custom:
  DeviceDatabase: ${cf.us-west-1:my-stack.DeviceDatabase}

As this issue is is from 2018 I don't know if this plugin is still in support

xyklex avatar Sep 10 '19 21:09 xyklex

provider
  environment:
    FOO: foo <-- I can get it in my tests with process.env
functions:
  MyFunction:
    environment:
      BAR: bar <-- I cannot

I did some testing and this seems to work as expected with latest version of the plugin and sls v1.58.0. I got both environment variables into the lambda.

KariHe avatar Nov 25 '19 09:11 KariHe

I'm having this same issue with cf variables being not populated on sls version: 1.51.0.

// variable in serverless.yaml
custom:
  DeviceDatabase: ${cf.us-west-1:my-stack.DeviceDatabase}

I will try to test this scenario. I'm not sure when Cloudformation references are resolved or are they handled actually the Cloudformation deployment.

As this issue is is from 2018 I don't know if this plugin is still in support

We currently don't have a much time to support these plugins, so we appreciate contributions to resolve the issues.

KariHe avatar Nov 25 '19 09:11 KariHe