-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot find a way to configure environment variables dynamically based on stage #79
Comments
@fredericbarthelet any help much appreciated thank you |
I am also experiencing this issue and would like a solution |
Completely useless feature, worse than a waste of time unless this is addresed |
I believe the params section can be used to achieve something close (empty env var vs not set).
|
@urg I don't see how that accomplishes what I asked for.. i.e. setting or leaving environment variable unset based on the stage. Where is the conditional logic in your example? What does putting the value in params accomplish? |
@colesiegel - see https://www.serverless.com/framework/docs/guides/parameters - the param corresponding to the stage is automatically set. Admittedly for this example the potentially something like the following might work to avoid setting at all (untested)
|
@colesiegel You can use dotenv before load configuration, for example:
|
I'd like to set up my environment variables based on the current
stage
.I initially tried to do this by referencing
${opt:stage}
directly in theserverless.ts
file, but I found that the value is not evaluated until the file is finished it's execution. As a result, I couldn't use the value of${opt:stage}
to determine my environment variables.I have also tried to compute the environment variables in a separate
serverless.config.js
file with a resolver function and import them following the steps here (https://www.serverless.com/framework/docs/providers/aws/guide/variables#exporting-a-function) but the problem is that I cannot set the aws lambda function environment to a variable reference like${self:custom.config.env}
as it expects an environment map of typeAwsLambdaEnvironment
rather than a string.Suppose I have a simple requirement - on the
local
stage there should exist an environment variable calledLOCAL_SNS_ENDPOINT
set tolocalhost:1234
and in all other stages this environment variable should not be set. Is there a way to do that withserverless.ts
? Due to the previously mentioned issues, I can't seem to dynamically include or exclude environment variables based on the stage.The text was updated successfully, but these errors were encountered: