@@ -8,7 +8,6 @@ const fs = require('fs-promise');
8
8
class ServerlessPlugin {
9
9
constructor ( serverless , options ) {
10
10
this . serverless = serverless ;
11
- this . options = options ;
12
11
13
12
this . commands = {
14
13
diff : {
@@ -39,23 +38,19 @@ class ServerlessPlugin {
39
38
'diff:diff' : this . diff . bind ( this ) ,
40
39
} ;
41
40
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
+ } ;
56
48
}
57
49
58
50
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 ( ) ;
59
54
let stackName ;
60
55
61
56
const orgTemplate = this . options . orgTemplate ;
@@ -65,7 +60,8 @@ class ServerlessPlugin {
65
60
&& this . serverless . service . provider . stackName !== '' ) {
66
61
stackName = this . serverless . service . provider . stackName ;
67
62
} 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 } ` ;
69
65
}
70
66
71
67
const params = {
@@ -75,7 +71,7 @@ class ServerlessPlugin {
75
71
76
72
this . serverless . cli . log ( 'Downloading currently deployed template' ) ;
77
73
78
- return this . cloudFormation . getTemplate ( params ) . promise ( )
74
+ return cloudFormation . getTemplate ( params ) . promise ( )
79
75
. then ( ( data ) => {
80
76
let templateBody = JSON . parse ( data . TemplateBody ) ;
81
77
templateBody = JSON . stringify ( templateBody , null , 2 ) ;
0 commit comments