Reference CLI Options

To reference CLI options that you passed, use the ${opt:<option>} syntax in your serverless.yml configuration file. It is valid to use the empty string in place of <option>. This looks like "${opt:}" and the result of declaring this in your serverless.yml is to embed the complete options object (i.e. all the command line options from your serverless command).

service: new-service
provider: aws
functions:
  hello:
    name: ${opt:stage}-hello
    handler: handler.hello
  world:
    name: ${opt:stage}-world
    handler: handler.world

In the above example, you're dynamically adding a prefix to the function names by referencing the stage option that you pass in the CLI when you run serverless deploy --stage dev. So when you deploy, the function name will always include the stage you're deploying to.

Edit this page

Reference CLI Options

To reference CLI options that you passed, use the ${opt:<option>} syntax in your serverless.yml configuration file. It is valid to use the empty string in place of <option>. This looks like "${opt:}" and the result of declaring this in your serverless.yml is to embed the complete options object (i.e. all the command line options from your serverless command).

service: new-service
provider: aws
functions:
  hello:
    name: ${opt:stage}-hello
    handler: handler.hello
  world:
    name: ${opt:stage}-world
    handler: handler.world

In the above example, you're dynamically adding a prefix to the function names by referencing the stage option that you pass in the CLI when you run serverless deploy --stage dev. So when you deploy, the function name will always include the stage you're deploying to.