Skip to content

Commit b93ced7

Browse files
committed
Remove option mutations. AWS validate lifecycle provided stage & region.
Before this patch, options.region would result in ‘us-east-1’ whenever the `-s` or `--stage` was not provided to the serverless command, confusing other plugins that work with the region specified in `serverless.yml` Now aws:common:validate is run first to calculate the variable substituted values required.
1 parent 7eaf631 commit b93ced7

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

lib/index.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const fs = require('fs-promise');
88
class ServerlessPlugin {
99
constructor(serverless, options) {
1010
this.serverless = serverless;
11-
this.options = options;
1211

1312
this.commands = {
1413
diff: {
@@ -39,23 +38,19 @@ class ServerlessPlugin {
3938
'diff:diff': this.diff.bind(this),
4039
};
4140

42-
this.options.stage = this.options.stage
43-
|| (this.serverless.service.defaults && this.serverless.service.defaults.stage)
44-
|| 'dev';
45-
this.options.region = this.options.region
46-
|| (this.serverless.service.defaults && this.serverless.service.defaults.region)
47-
|| 'us-east-1';
48-
this.options.diffTool = this.options.diffTool;
49-
this.options.localTemplate = this.options.localTemplate
50-
|| '.serverless/cloudformation-template-update-stack.json';
51-
this.options.orgTemplate = this.options.localTemplate.replace('.json', '.org.json');
52-
53-
AWS.config.update({ region: this.options.region });
54-
55-
this.cloudFormation = new AWS.CloudFormation();
41+
let localTemplate = options.localTemplate || '.serverless/cloudformation-template-update-stack.json';
42+
let orgTemplate = localTemplate.replace('.json', '.org.json');
43+
this.options = {
44+
diffTool: options.diffTool,
45+
localTemplate,
46+
orgTemplate,
47+
};
5648
}
5749

5850
downloadTemplate() {
51+
this.serverless.pluginManager.spawn('aws:common:validate');
52+
AWS.config.update({ region: this.serverless.getProvider('aws').getRegion() });
53+
let cloudFormation = new AWS.CloudFormation();
5954
let stackName;
6055

6156
const orgTemplate = this.options.orgTemplate;
@@ -65,7 +60,8 @@ class ServerlessPlugin {
6560
&& this.serverless.service.provider.stackName !== '') {
6661
stackName = this.serverless.service.provider.stackName;
6762
} else {
68-
stackName = `${this.serverless.service.service}-${this.options.stage}`;
63+
let stage = this.serverless.getProvider('aws').getStage();
64+
stackName = `${this.serverless.service.service}-${stage}`;
6965
}
7066

7167
const params = {
@@ -75,7 +71,7 @@ class ServerlessPlugin {
7571

7672
this.serverless.cli.log('Downloading currently deployed template');
7773

78-
return this.cloudFormation.getTemplate(params).promise()
74+
return cloudFormation.getTemplate(params).promise()
7975
.then((data) => {
8076
let templateBody = JSON.parse(data.TemplateBody);
8177
templateBody = JSON.stringify(templateBody, null, 2);

0 commit comments

Comments
 (0)