Skip to content

Instantly share code, notes, and snippets.

@jsonw23
Last active June 24, 2020 03:22
Show Gist options
  • Select an option

  • Save jsonw23/e8c9265ca5d93ebeff8e4a9bd549b95d to your computer and use it in GitHub Desktop.

Select an option

Save jsonw23/e8c9265ca5d93ebeff8e4a9bd549b95d to your computer and use it in GitHub Desktop.
Environment variable mapping based on DeploymentStage parameter
Mappings:
EnvironmentVariables:
# mapping keys are the allowed values for DeploymentStage
  staging:
# mapping value is multi-value where key is the environment variable
  PROD: false
  API_URL: {staging api endpoint url}
  production:
  PROD: true
  API_URL: {production api endpoint url}
Resources:
HelloWorldFunction:
# ...
Environment:
Variables:
STAGE: !Ref DeploymentStage
# instrinsic FindInMap function looks up the value by the deployment stage and the env var name
PROD: !FindInMap [EnvironmentVariables, !Ref DeploymentStage, PROD]
API_URL: !FindInMap [EnvironmentVariables, !Ref DeploymentStage, API_URL]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment