arabold / serverless-export-env

Serverless plugin to export environment variables into a .env file
MIT License
103 stars 34 forks source link

Function environment variables with different values #17

Closed coyoteecd closed 3 years ago

coyoteecd commented 4 years ago

The plugin seems to assume that environment variable names are unique across all functions in the serverless.yml stack and lumps them together in a name=value list within .env file. This may or may not be the case in practice.

Example serverless.yml:

plugins:
  - serverless-offline
  - serverless-export-env
[...]
functions:
  one-function:
    handler: src/one.handler
    environment:
      test: one

  other-function:
    handler: src/other.handler
    environment:
      test: other

With the plugin, invoking one-function shows process.env.test as two. Without the plugin, process.env.test is correctly set to one.

arabold commented 4 years ago

This seems like a useful feature request. I'm not perfectly sure how we could achieve this, e.g. we would need to create .env files for every function, but I'm happy to look into any future pull requests trying to tackle this.

arabold commented 3 years ago

v2.0.0 allows to export environment variables for a specific function only. To simplify testing the new version, I've published 2.0.0-alpha.0 as alpha release to npm:

npm install serverless-export-env@2.0.0-alpha.0 --save-dev

I'm closing this task. Please open a new one (or comment on this one) if your problems are still not solved.