Giter Club home page Giter Club logo

Comments (10)

ChristopheBougere avatar ChristopheBougere commented on July 27, 2024 4

I'm having a similar use case: I want to load env variables in my fargate task definition, but not in my lambda functions.
Your snippet should work if you add this setting:

custom:
  dotenv:
    include: [] # Do not inject env variables into lambdas

Having an option to disable auto injection could be great by the way :)

from serverless-dotenv-plugin.

redlickigrzegorz avatar redlickigrzegorz commented on July 27, 2024 1

@colynb Yes, of course, and I believe that it will be a simple example 😉

functions:
  sample-funtion-a:
    handler: src/handler.sampleFunctionA
    environment:
      SAMPLE_A: ${env:SAMPLE_A}
  sample-funtion-b:
    handler: src/handler.sampleFunctionB
    environment:
      SAMPLE_B: ${env:SAMPLE_B}

With the current functionality, we will get SAMPLE_A and SAMPLE_B in the environment section of both functions.

from serverless-dotenv-plugin.

redlickigrzegorz avatar redlickigrzegorz commented on July 27, 2024

It's a very good question. I didn't find any possibility to set this with the usage of this library that's why I decided to create my own config.js file to keep all the needed env variables and put them where I want during the work with serverless 😃

@colynb is it possible to do this via your library?

from serverless-dotenv-plugin.

colynb avatar colynb commented on July 27, 2024

Would you mind describing a use-case/scenario so that I can get a better understanding? Thanks

from serverless-dotenv-plugin.

tommykamkcm avatar tommykamkcm commented on July 27, 2024

@colynb Yes, of course, and I believe that it will be a simple example 😉

functions:
  sample-funtion-a:
    handler: src/handler.sampleFunctionA
    environment:
      SAMPLE_A: ${env:SAMPLE_A}
  sample-funtion-b:
    handler: src/handler.sampleFunctionB
    environment:
      SAMPLE_B: ${env:SAMPLE_B}

With the current functionality, we will get SAMPLE_A and SAMPLE_B in the environment section of both functions.

Hello everyone, I have additional questions about this scenario:

Assuming there are 10 env vars declared in .env e.g. SAMPLE_A ... SAMPLE_J
What happens to sample-funtion-a if we declare:

  • SAMPLE_C ... SAMPLE_J under custom > dotenv > include, and also

  • SAMPLE_A under sample-function-a

will sample-function-a get all the env vars except SAMPLE_B?

from serverless-dotenv-plugin.

krlozadan avatar krlozadan commented on July 27, 2024

Hi, any updates on this?

@colynb Yes, of course, and I believe that it will be a simple example 😉

functions:
  sample-funtion-a:
    handler: src/handler.sampleFunctionA
    environment:
      SAMPLE_A: ${env:SAMPLE_A}
  sample-funtion-b:
    handler: src/handler.sampleFunctionB
    environment:
      SAMPLE_B: ${env:SAMPLE_B}

With the current functionality, we will get SAMPLE_A and SAMPLE_B in the environment section of both functions.

This will definitely be very helpful

from serverless-dotenv-plugin.

colynb avatar colynb commented on July 27, 2024

@krlozadan sorry for the VERY late response. I've been using today to get caught up on this plugin. As I mentioned in a few other issues here recently, I'm extremely nervous about accidentally introducing breaking changes so I erred on the side of simply ignoring these requests.

With that said, this is definitely one of the trickier requests to implement. I'm not sure how I would even approach it.

from serverless-dotenv-plugin.

neverendingqs avatar neverendingqs commented on July 27, 2024

@colynb Yes, of course, and I believe that it will be a simple example wink

functions:
  sample-funtion-a:
    handler: src/handler.sampleFunctionA
    environment:
      SAMPLE_A: ${env:SAMPLE_A}
  sample-funtion-b:
    handler: src/handler.sampleFunctionB
    environment:
      SAMPLE_B: ${env:SAMPLE_B}

With the current functionality, we will get SAMPLE_A and SAMPLE_B in the environment section of both functions.

Hello everyone, I have additional questions about this scenario:

Assuming there are 10 env vars declared in .env e.g. SAMPLE_A ... SAMPLE_J
What happens to sample-funtion-a if we declare:

  • SAMPLE_C ... SAMPLE_J under custom > dotenv > include, and also
  • SAMPLE_A under sample-function-a

will sample-function-a get all the env vars except SAMPLE_B?

I am 90+% sure of the following. Please test my statements below if you would like to be 100% sure.

Environment variables defined with dotenv end up at the project level according to

Object.keys(envVars).forEach((key) => {
this.log('\t - ' + key)
this.serverless.service.provider.environment[key] = envVars[key]
.

In your example, sample-function-a will include SAMPLE_B ... SAMPLE_J from the dotenv file(s) because it pulls it from the project level.

Furthermore, environment variables with the same name defined at the function name takes precedence over ones defined at a project level. This means sample-function-a's SAMPLE_A value is whatever you declare it to be. In your example, because you set it to ${env:SAMPLE_A}, sample-function-a's SAMPLE_A value will be the same as the one in the dotenv file(s).

from serverless-dotenv-plugin.

neverendingqs avatar neverendingqs commented on July 27, 2024

I'm having a similar use case: I want to load env variables in my fargate task definition, but not in my lambda functions.
Your snippet should work if you add this setting:

custom:
  dotenv:
    include: [] # Do not inject env variables into lambdas

Having an option to disable auto injection could be great by the way :)

This is my recommendation as well. Please see #89 for details.

from serverless-dotenv-plugin.

neverendingqs avatar neverendingqs commented on July 27, 2024

I think all questions have been answered. Because there are a variety of questions here, if you have a follow-up question or a related question, please post it in https://github.com/neverendingqs/serverless-dotenv-plugin/discussions/categories/q-a.

Thanks!

from serverless-dotenv-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.