Comments (10)
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.
@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.
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.
Would you mind describing a use-case/scenario so that I can get a better understanding? Thanks
from serverless-dotenv-plugin.
@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
andSAMPLE_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
undersample-function-a
will sample-function-a
get all the env vars except SAMPLE_B
?
from serverless-dotenv-plugin.
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
andSAMPLE_B
in the environment section of both functions.
This will definitely be very helpful
from serverless-dotenv-plugin.
@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.
@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
andSAMPLE_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 tosample-funtion-a
if we declare:
SAMPLE_C
...SAMPLE_J
under custom > dotenv > include, and alsoSAMPLE_A
undersample-function-a
will
sample-function-a
get all the env vars exceptSAMPLE_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
serverless-dotenv-plugin/index.js
Lines 120 to 122 in 2b66c15
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.
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 lambdasHaving 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.
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)
- Plugin should throw on error.
- Release GitHub action workflow only works if there is no branch protection. HOT 1
- Warn when incompatible options are set
- Automatic env file resolution is in reverse order of precedence HOT 7
- Create npmignore file
- Release (next)
- Consider how new variables engine in serverless could improve or impact this plugin HOT 2
- Document differences between Serverless's .env resolution and this plugin HOT 1
- NODE_ENV and stage collides to each other HOT 3
- System environment variables (wrongly) take higher precedence than the .env file HOT 7
- Cannot have parameterized `stage` and `region` HOT 2
- Serverless Framework v3: integrating with the new design
- Can't read multi line env variable - v2.62.0 HOT 2
- Not loading env file from stage param HOT 3
- basePath not getting resolve HOT 3
- Allow ability to set default environment name. HOT 2
- Feature Request: Add `envFile` to configuration.
- Question : setting env var HOT 1
- Fix links in package.json
- Add a pull request template
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-dotenv-plugin.