Always require stage parameter for Serverless framework

Viewed 1104

Is there a way to make Serverless abort execution if the stage is not given?

Looks like it defaults to "dev", which is not preferred in a multi-environment setup where a "default" environment doesn't exist.

The closest I could get was reading a 'stage' config variable from a local file. Unfortunately Serverless still defaults to 'dev' if the stage variable is missing from the (existing) local file. It does give a warning for the missing variable, though.

provider:
  name: aws
  runtime: nodejs8.10
  region: eu-west-1
  stage: ${file(serverless-local.yml):stage}
2 Answers

This is a bit of guessing since I'm new to serverless framework, but you can set the default value that is used when value is not provided with command line option.

The following will set the default value to dev.

provider:
  stage: ${opt:stage, 'dev'}

Now, if you set the default value to empty or something that does not exist, i.e. foobar, maybe then you'll get the wanted effect and have the execution abort.

Also, the documentation on overwriting variables might give other helpful tips in this case.

Related