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.

Allow for optional environment variables

See original GitHub issue

Is 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:closed
  • Created 2 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
GurmeharScommented, Dec 2, 2021

@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 😄

2reactions
perrin4869commented, Dec 2, 2021

@KrishnaSolo @GurmeharS thank you so much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional environment variables in Spring app - Stack Overflow
First, if SOME_ENV_VARIABLE is not found when application.properties is being processed, its value becomes the string literal "#{null}". Then, @ ...
Read more >
Optional environment variables - Aidbox documentation
Optional environment variables ... These parameters will enable SSL connection from Aidbox to postgresql Docs on JDBC PostgreSQL connection string are here: ...
Read more >
Optional environment variable settings - IBM Cloud Pak for Data
The following environment variables are recommended to assist in job flow design. Parent topic: Guide to setting environment variables.
Read more >
Environment variables in Compose | Docker Documentation
You can set default values for environment variables using a .env file, which Compose automatically looks for in project directory (parent folder of...
Read more >
Optional environment variables setting
Procedures use these variables at runtime. You must define them to enable procedures to reference valid values. Search: Column.
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