@@ -49,16 +49,16 @@ class WarmUP {
49
49
* */
50
50
afterPackageInitialize ( ) {
51
51
// See https://github.com/serverless/serverless/issues/2631
52
- this . options . stage = this . options . stage
53
- || this . serverless . service . provider . stage
54
- || ( this . serverless . service . defaults && this . serverless . service . defaults . stage )
55
- || 'dev'
56
- this . options . region = this . options . region
57
- || this . serverless . service . provider . region
58
- || ( this . serverless . service . defaults && this . serverless . service . defaults . region )
59
- || 'us-east-1'
52
+ this . options . stage = this . options . stage ||
53
+ this . serverless . service . provider . stage ||
54
+ ( this . serverless . service . defaults && this . serverless . service . defaults . stage ) ||
55
+ 'dev'
56
+ this . options . region = this . options . region ||
57
+ this . serverless . service . provider . region ||
58
+ ( this . serverless . service . defaults && this . serverless . service . defaults . region ) ||
59
+ 'us-east-1'
60
60
this . custom = this . serverless . service . custom
61
-
61
+
62
62
this . configPlugin ( )
63
63
return this . createWarmer ( )
64
64
}
@@ -260,37 +260,35 @@ class WarmUP {
260
260
return functionObject . name
261
261
} )
262
262
263
- /** Write function invoke promises and push to array */
264
263
const warmUpFunction = `"use strict";
265
264
266
265
/** Generated by Serverless WarmUP Plugin at ${ new Date ( ) . toISOString ( ) } */
267
266
const aws = require("aws-sdk");
268
267
aws.config.region = "${ this . options . region } ";
269
268
const lambda = new aws.Lambda();
270
- const functionNames = "${ functionNames . join ( ) } ".split(",");
271
- module.exports.warmUp = (event, context, callback) => {
272
- let invokes = [];
273
- let errors = 0;
269
+ const functionNames = ${ JSON . stringify ( functionNames ) } ;
270
+ module.exports.warmUp = async (event, context, callback) => {
274
271
console.log("Warm Up Start");
275
- functionNames.forEach( (functionName) => {
272
+ const invokes = await Promise.all( functionNames.map(async (functionName) => {
276
273
const params = {
277
274
FunctionName: functionName,
278
275
InvocationType: "RequestResponse",
279
276
LogType: "None",
280
277
Qualifier: process.env.SERVERLESS_ALIAS || "$LATEST",
281
- Payload: JSON.stringify({ source: " serverless-plugin-warmup" })
278
+ Payload: ' ${ JSON . stringify ( { source : ' serverless-plugin-warmup' } ) } '
282
279
};
283
- invokes.push(lambda.invoke(params).promise().then((data) => {
284
- console.log("Warm Up Invoke Success: " + functionName, data);
285
- }, (error) => {
286
- errors++;
287
- console.log("Warm Up Invoke Error: " + functionName, error);
288
- }));
289
- });
290
- Promise.all(invokes).then(() => {
291
- console.log("Warm Up Finished with " + errors + " invoke errors");
292
- callback();
293
- });
280
+
281
+ try {
282
+ const data = await lambda.invoke(params).promise();
283
+ console.log(\`Warm Up Invoke Success: \${functionName}\`, data);
284
+ return true;
285
+ } catch (e) {
286
+ console.log(\`Warm Up Invoke Error: \${functionName}\`, e);
287
+ return false;
288
+ }
289
+ }));
290
+
291
+ console.log(\`Warm Up Finished with \${invokes.filter(r => !r).length} invoke errors\`);
294
292
}`
295
293
296
294
/** Write warm up file */
@@ -310,7 +308,7 @@ module.exports.warmUp = (event, context, callback) => {
310
308
handler : this . pathHandler ,
311
309
memorySize : this . warmup . memorySize ,
312
310
name : this . warmup . name ,
313
- runtime : 'nodejs6 .10' ,
311
+ runtime : 'nodejs8 .10' ,
314
312
package : {
315
313
individually : true ,
316
314
exclude : [ '**' ] ,
0 commit comments