Allow for optional environment variables
See original GitHub issueIs there an existing issue for this?
- I have searched existing issues, it hasn’t been reported yet
Use case description
This issue is related to https://github.com/serverless/serverless/issues/3491 Currently, setting something like:
provider:
name: aws
runtime: nodejs14.x
environment:
MYVAR: ${env:MYVAR, null}
Will result in MYVAR
being set to the string "undefined"
when process.env.MYVAR
is not present. I think that by explicitly setting null
when no value is found, the intent is for this environment variable to not be present in the final lambda.
Proposed solution (optional)
Environment variables that are set to allow null
explicitly should not be present in the final lambda.
Implementation proposal
(Added by maintainers)
Serverless Framework clear all null values from the CF template (we allow those values in general logic, but before sending template to AWS we remove them, as it’s not supported value type on CF side).
It happens here: https://github.com/serverless/serverless/blob/d52526bb6059ce20eba341c29ad5a2373c238624/lib/plugins/aws/package/lib/stripNullPropsFromTemplateResources.js
However, it clears nulls only from top-level properties, when actually we need to traverse all properties deeply. (environment variable settings are located at Properties.Environment[VAR NAME]
).
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (10 by maintainers)
@medikoo Hi, worked on this with @KrishnaSolo and a few friends as a part of a class assignment to contribute to an open source project.
Submitted a PR here: #10304, please let me/us know what you think!
Thanks 😄
@KrishnaSolo @GurmeharS thank you so much!