Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
serverless-plugin-env-stage-config
Advanced tools
Serverless plugin to define environment variables files for stages
This Serverless plugin allows to define environment variable configuration files for stages.
It exposes a new variable resolver ($esc
) that automatically picks the correct value based on the selected stage.
For development stages (local
, dev
, development
), the variables will default to the system’s environment variables.
yarn add --dev serverless-plugin-env-stage-config
plugins:
- serverless-plugin-env-stage-config
For non-development stages, the variables will be retrieved from a serverless.env.${stage}.yml
file, alongside the serverless.yml
.
Let’s consider the following serverless.yml
:
name: my-service
useDotenv: true
provider:
name: aws
environment:
MYSQL_HOST: ${esc:MYSQL_HOST}
MYSQL_PORT: ${esc:MYSQL_PORT}
functions:
run-something:
handler: handler.run
environment:
SECRET_TOKEN: ${esc:SECRET_TOKEN}
In a local environment, the variables resolved with the esc:
prefix will be equivalent to using env:
. Using useDotenv: true
alongside a .env
file will alow you to define your environement variables in the environement.
The support local stages are:
If you need to define a different source for the environement variables for your prod
stage, you can define a serverless.env.prod.yml
to redefine the variables.
For example, if you’re using AWS SSM Parameter Store, you could create the following file:
MYSQL_HOST: ${ssm:/my-service/prod/MYSQL_HOST~true}
SECRET_TOKEN: ${ssm:/my-service/prod/SECRET_TOKEN~true}
Any variable that is not included in the serverless.env.prod.yml
file will produce a warning and fallback to using env:
.
In this case, you will get the following warning:
Serverless: env-stage-config: WARNING: the MYSQL_PORT variable is not defined in serverless.env.prod.yml, defaulting to ${env:MYSQL_PORT}.
MIT
╚⊙ ⊙╝
╚═(███)═╝
╚═(███)═╝
╚═(███)═╝
╚═(███)═╝
╚═(███)═╝
╚═(███)═╝
FAQs
Serverless plugin to define environment variables files for stages
The npm package serverless-plugin-env-stage-config receives a total of 177 weekly downloads. As such, serverless-plugin-env-stage-config popularity was classified as not popular.
We found that serverless-plugin-env-stage-config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.