From 7cf3ec4e2e5bbf33bd037f604fad2f6f1c2ddded Mon Sep 17 00:00:00 2001 From: David Wells Date: Thu, 21 Sep 2017 16:43:55 -0700 Subject: [PATCH] Update variables.md --- docs/providers/aws/guide/variables.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/providers/aws/guide/variables.md b/docs/providers/aws/guide/variables.md index 8f4fc14ac..581b7b95e 100644 --- a/docs/providers/aws/guide/variables.md +++ b/docs/providers/aws/guide/variables.md @@ -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