Updated on 2023-11-22 GMT+08:00

Variables

The Serverless Framework provides a powerful variable system which allows you to add dynamic data into your serverless.yml. With Serverless variables, you will be able to do the following:

  • Reference & load environment variables.
  • Reference & load variables from CLI options.
  • Recursively reference properties of any type from the same serverless.yml file.
  • Recursively reference properties of any type from other YAML or JSON files.
  • Recursively nest variable references for ultimate flexibility.
  • Combine multiple variable references to overwrite each other.

You can only use variables in values attribute instead of key attribute in serverless.yml. So you cannot use variables to generate dynamic logical IDs in the custom resources.

Referencing Environment Variables

To reference environment variables, use the ${env:someProperty} syntax in your serverless.yml.
service: new-service

provider:
  name: huawei
  runtime: Node.js14.18
  credentials: ~/.fg/credentials # path must be absolute
  environment:
    variables:
      ENV_FIRST: ${env:TENCENTCLOUD_APPID}

plugins:
  - serverless-huawei-functions

functions:
  hello:
    handler: index.hello