Skip to content

Commit 083b0e2

Browse files
authored
Merge pull request #71 from juanjoDiaz/update_to_node_8
Update to node 8
2 parents b56bc1b + 245cc7c commit 083b0e2

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

src/index.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ class WarmUP {
4949
* */
5050
afterPackageInitialize () {
5151
// 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'
6060
this.custom = this.serverless.service.custom
61-
61+
6262
this.configPlugin()
6363
return this.createWarmer()
6464
}
@@ -260,37 +260,35 @@ class WarmUP {
260260
return functionObject.name
261261
})
262262

263-
/** Write function invoke promises and push to array */
264263
const warmUpFunction = `"use strict";
265264
266265
/** Generated by Serverless WarmUP Plugin at ${new Date().toISOString()} */
267266
const aws = require("aws-sdk");
268267
aws.config.region = "${this.options.region}";
269268
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) => {
274271
console.log("Warm Up Start");
275-
functionNames.forEach((functionName) => {
272+
const invokes = await Promise.all(functionNames.map(async (functionName) => {
276273
const params = {
277274
FunctionName: functionName,
278275
InvocationType: "RequestResponse",
279276
LogType: "None",
280277
Qualifier: process.env.SERVERLESS_ALIAS || "$LATEST",
281-
Payload: JSON.stringify({ source: "serverless-plugin-warmup" })
278+
Payload: '${JSON.stringify({ source: 'serverless-plugin-warmup' })}'
282279
};
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\`);
294292
}`
295293

296294
/** Write warm up file */
@@ -310,7 +308,7 @@ module.exports.warmUp = (event, context, callback) => {
310308
handler: this.pathHandler,
311309
memorySize: this.warmup.memorySize,
312310
name: this.warmup.name,
313-
runtime: 'nodejs6.10',
311+
runtime: 'nodejs8.10',
314312
package: {
315313
individually: true,
316314
exclude: ['**'],

0 commit comments

Comments
 (0)