Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The --stage cli option is not passed to stage property if omitted from serverless.yml file #7990

Open
tonyallain opened this issue Jul 26, 2020 · 1 comment
Assignees
Labels

Comments

@tonyallain
Copy link

tonyallain commented Jul 26, 2020

When stage is missing from serverless.yml it will not automatically resolve to a passed in --stage argument, but instead remain as dev. This is dissimilar to the behavior of region which (if omitted from the yml file) will resolve to the passed in --region argument.

This issue was discovered when configuring a plugin to set defaults if none are provided such as VPC configuration and the boilerplate stage and region options/fallbacks.

serverless.yml
service: stage-bug

plugins:
  - ./plugin

provider:
  name: aws
  runtime: nodejs12.x
plugin.js
'use strict';

class ServerlessPlugin {
  constructor(serverless, options) {
    this.serverless = serverless;
    this.options = options;

    this.commands = {};

    this.hooks = {};

    console.log(this.serverless.service.provider);
  }
}

module.exports = ServerlessPlugin;
sls --version --stage production --region potato output
{ stage: 'dev',
  variableSyntax: '\\${([^{}]+?)}',
  name: 'aws',
  runtime: 'nodejs12.x',
  region: 'potato',
  versionFunctions: true,
  remoteFunctionData: null }

Installed version

Framework Core: 1.76.1
Plugin: 3.6.17
SDK: 2.3.1
Components: 2.33.0
@medikoo
Copy link
Contributor

medikoo commented Jul 27, 2020

@tonyallain it's actually expected, as service.provider.stage is configured to expose stage as in serverless.yml (eventually defaulting to dev). It's not a source of information for fully resolved stage.

For fully resolved stage use this.serverless.getProvider('aws').getStage().

I agree it's sort of design issue as it's counter-intuitive, but it's it is what it is (at least at this point) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants