Support for `provider.environment` in `serverless.yml`
I noticed that provider.environment: {} wasn't being pushed down to scripts.
This PR will allow scripts to utilize environment variables defined in provider.environment.
hi @weixu365 ! let me know what you think of this PR! thank you!
hi @weixu365 could you have a look at this PR? thank you!
Just realise that the ecmaVersion need to be changed in eslint config for the optional chaining operator:
parserOptions:
ecmaVersion: 2020
hi @weixu365 for my use case I have a hook on offline:start which runs database migrations at startup. the table name is dynamic based on Serverless stage and that logic is done using Serverless interpolation on provider.environment, e.g.
serverless.yml
provider:
environment:
TABLE_NAME: some-table-${opt:stage, "development"}
this allows TABLE_NAME to be available for the migration script during the hook
Can you change the ecmaVersion to 2020 in .eslintrc file? it's required by the optional chaining operator:
parserOptions:
ecmaVersion: 2020
@weixu365 done! could you allow the unit tests to run?
@weixu365 another question... should we create a custom.scriptable.environment[] so that this feature is opt-in?
custom:
scriptable:
environment:
- process # the default
# opt in for this feature:
# - serverless
hooks:
serverless:offline: echo "env is $(env)"
Or alternatively, bump the major version on this project since this fundamentally changes how "environment" gets set when a process runs?
I'll fix the codecov failure asap
I think it should be compatible with the current version if we change the code to
...(this.serverless?.service?.provider?.environment || {}),
...(process.env || {}),
It's also a good idea to use the opt-in feature which explicitly set the environment for the plugin
environment: - process # the default # opt in for this feature: # - serverless
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 20 days. Thank you for your contributions.
I would have also liked this feature.
I'm currently trying to create a workflow where I deploy a web app to a s3 bucket using serverless. I've used hooks to run npm run build prior to serverless-s3-sync uploading the build web app to an s3 bucket. However, I would want my environment variables to be set for the build for the appropriate stage etc.
I think this pull request would have helped me do this.