typescript
typescript copied to clipboard
Cannot find a way to configure environment variables dynamically based on stage
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 the serverless.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 type AwsLambdaEnvironment
rather than a string.
Suppose I have a simple requirement - on the local
stage there should exist an environment variable called LOCAL_SNS_ENDPOINT
set to localhost:1234
and in all other stages this environment variable should not be set. Is there a way to do that with serverless.ts
? Due to the previously mentioned issues, I can't seem to dynamically include or exclude environment variables based on the stage.