mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Update variables.md
This commit is contained in:
parent
94d8be2c4d
commit
7cf3ec4e2e
@ -20,9 +20,11 @@ They are especially useful when providing secrets for your service to use and wh
|
||||
|
||||
To use variables, you will need to reference values enclosed in `${}`.
|
||||
|
||||
```
|
||||
yamlKeyXYZ: ${variableSource}
|
||||
```yml
|
||||
# see current variable sources list below
|
||||
yamlKeyXYZ: ${variableSource}
|
||||
# this is an example of providing a default value as the second parameter
|
||||
otherYamlKey: ${variableSource, defaultValue}
|
||||
```
|
||||
|
||||
You can define your own variable syntax (regex) if it conflicts with CloudFormation's syntax
|
||||
@ -40,6 +42,18 @@ You can define your own variable syntax (regex) if it conflicts with CloudFormat
|
||||
|
||||
You can also **Recursively reference properties** with the variable system. This means you can combine multiple values and variable sources for a lot of flexibility.
|
||||
|
||||
For example:
|
||||
|
||||
```yml
|
||||
provider:
|
||||
name: aws
|
||||
stage: ${opt:stage, 'dev'}
|
||||
environment:
|
||||
MY_SECRET: ${file(./config.${self:provider.stage}.json):SECRET}
|
||||
```
|
||||
|
||||
If `--stage dev` is supplied as an option then `${file(./config.${self:provider.stage}.json):SECRET}` is references the `config.dev.json` file
|
||||
|
||||
**Note:** You can only use variables in `serverless.yml` property **values**, not property keys. So you can't use variables to generate dynamic logical IDs in the custom resources section for example.
|
||||
|
||||
## Reference Properties In serverless.yml
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user