@@ -5,6 +5,7 @@ const _ = require('lodash');
5
5
const utils = require ( './utils' ) ;
6
6
7
7
const NO_UPDATE_MESSAGE = 'No updates are to be performed.' ;
8
+ const TEMPLATE_MIN_SIZE_FOR_UPLOAD = 51200 ;
8
9
9
10
module . exports = {
10
11
@@ -135,7 +136,7 @@ module.exports = {
135
136
} ) ;
136
137
} ,
137
138
138
- aliasApplyStackChanges ( currentTemplate , aliasStackTemplates , currentAliasStackTemplate ) {
139
+ aliasApplyStackChanges ( currentTemplate , aliasStackTemplates , currentAliasStackTemplate , templateUrl ) {
139
140
140
141
const stackName = this . _provider . naming . getStackName ( ) ;
141
142
@@ -155,10 +156,15 @@ module.exports = {
155
156
'CAPABILITY_NAMED_IAM' ,
156
157
] ,
157
158
Parameters : [ ] ,
158
- TemplateBody : JSON . stringify ( currentTemplate ) ,
159
159
Tags : _ . map ( _ . keys ( stackTags ) , key => ( { Key : key , Value : stackTags [ key ] } ) ) ,
160
160
} ;
161
161
162
+ if ( templateUrl ) {
163
+ params . TemplateURL = templateUrl ;
164
+ } else {
165
+ params . TemplateBody = JSON . stringify ( currentTemplate ) ;
166
+ }
167
+
162
168
this . options . verbose && this . _serverless . cli . log ( `Checking stack policy` ) ;
163
169
164
170
// Policy must have at least one statement, otherwise no updates would be possible at all
@@ -185,8 +191,38 @@ module.exports = {
185
191
186
192
} ,
187
193
194
+ uploadCloudFormationTemplate ( currentTemplate , aliasStackTemplates , currentAliasStackTemplate ) {
195
+ const templateSize = JSON . stringify ( currentTemplate ) . length ;
196
+ if ( templateSize < TEMPLATE_MIN_SIZE_FOR_UPLOAD ) {
197
+ this . serverless . cli . log ( `Skipping Upload of CloudFormation alias file to S3, size is only ${ templateSize } ` ) ;
198
+ return BbPromise . resolve ( [ currentTemplate , aliasStackTemplates , currentAliasStackTemplate ] ) ;
199
+ }
200
+ this . serverless . cli . log ( 'Uploading CloudFormation alias file to S3...' ) ;
201
+ const body = JSON . stringify ( currentTemplate ) ;
202
+
203
+ const fileName = 'compiled-cloudformation-template-alias.json' ;
204
+
205
+ let params = {
206
+ Bucket : this . bucketName ,
207
+ Key : `${ this . serverless . service . package . artifactDirectoryName } /${ fileName } ` ,
208
+ Body : body ,
209
+ ContentType : 'application/json' ,
210
+ } ;
211
+
212
+ return this . provider . request ( 'S3' ,
213
+ 'putObject' ,
214
+ params ,
215
+ this . _options . stage ,
216
+ this . _options . region )
217
+ . then ( ( ) => {
218
+ const templateUrl = `https://s3.amazonaws.com/${ this . bucketName } /${ this . _serverless . service . package . artifactDirectoryName } /compiled-cloudformation-template-alias.json` ;
219
+ return BbPromise . resolve ( [ currentTemplate , aliasStackTemplates , currentAliasStackTemplate , templateUrl ] ) ;
220
+ } ) ;
221
+ } ,
222
+
188
223
aliasRemoveAliasStack ( currentTemplate , aliasStackTemplates , currentAliasStackTemplate ) {
189
224
225
+
190
226
const stackName = `${ this . _provider . naming . getStackName ( ) } -${ this . _alias } ` ;
191
227
192
228
this . options . verbose && this . _serverless . cli . log ( `Removing CF stack ${ stackName } ` ) ;
@@ -245,9 +281,8 @@ module.exports = {
245
281
return BbPromise . resolve ( [ currentTemplate , aliasStackTemplates , currentAliasStackTemplate ] ) . bind ( this )
246
282
. spread ( this . aliasCreateStackChanges )
247
283
. spread ( this . aliasRemoveAliasStack )
284
+ . spread ( this . uploadCloudFormationTemplate )
248
285
. spread ( this . aliasApplyStackChanges )
249
286
. then ( ( ) => BbPromise . resolve ( ) ) ;
250
-
251
287
}
252
-
253
288
} ;
0 commit comments