docs/sf/guides/parameters.md
Parameters can be defined in serverless.yml, Serverless Dashboard or passed via CLI with --param="<key>=<value>" flag. They can be used for example to:
Parameters can be passed directly via CLI --param flag, following the pattern --param="<key>=<value>":
serverless deploy --param="domain=myapp.com" --param="key=value"
Parameters can then be used via the ${param:XXX} variables:
provider:
environment:
APP_DOMAIN: ${param:domain}
KEY: ${param:key}
stages allows you to set Parameters and other configuration details in a Stage-specific way. This is the new, preferred method for defining Parameters, which was launched in V.4. We'll be launching many features for the stages property, so we recommend embracing it.
Parameters can be defined for each stage in serverless.yml under the stages.<stage>.params key:
stages:
prod:
params:
domain: myapp.com
dev:
params:
domain: preview.myapp.com
Use the default key to define parameters that apply to all stages by default:
stages:
default:
params:
domain: ${sls:stage}.preview.myapp.com
prod:
params:
domain: myapp.com
dev:
params:
domain: preview.myapp.com
Parameters can then be used via the ${param:XXX} variables:
provider:
environment:
APP_DOMAIN: ${param:domain}
The variable will be resolved based on the current stage.
You can also set stage-specific parameters using the params top-level property, as show below. However, using the stages top-level property as shown above is the preferred and recommended way of setting parameters in the Serverless Framework V4.
# serverless.yml
params:
default:
domain: ${sls:stage}.myapi.com
prod:
domain: myapi.com
dev:
domain: dev.myapi.com
Serverless Dashboard lets you create and manage parameters, which is perfect for storing secrets securely or sharing configuration values across team members.
On top of that, Dashboard parameters can be stored on the service (applies to all stages) or on a specific instance (applies to a specific stage).
Dashboard parameters are treated as sensitive values, they are always encrypted at rest, and only decrypted during deployment or to view them in the dashboard.
Just like any other parameter, they can be used in serverless.yml via the ${param:XXX} variables:
provider:
environment:
STRIPE_SECRET_KEY: ${param:stripeSecret}
Parameters can be created in the Dashboard at the service level (applies to all stages) or instance level (stage-specific).
To manage parameters on a service, go to the apps section of the dashboard, and select settings under the ... menu.
To manage parameters on an instance, go to the app section of the dashboard, select the instance, and go to the params tab.
Parameters can be defined in serverless.yml per stage, as well as in Serverless Dashboard on the service or the instance (stage). Here is the priority used to resolve a ${param:XXX} variable:
--param CLI flagstages.<stage>.params in serverless.ymlstages.default.params in serverless.yml${param:XXX, 'default value'}This gives you flexibility to mix serverless.yml parameters as well as secure Serverless Dashboard parameters.
This is especially useful in development when deploying to ephemeral stages (e.g. "feature-x"). The stage might not have any parameter, therefore it will default to the parameters set on the service. However, in other stages, like "prod", or "staging", you may override the service-level parameters with stage-level parameters to use values unique to that stage.