serverless-plugin-warmup 7.0.2 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,6 +44,7 @@ custom:
44
44
  events:
45
45
  - schedule: cron(0/5 8-17 ? * MON-FRI *)
46
46
  concurrency: 10
47
+ verbose: true
47
48
  logRetentionInDays: 10
48
49
  outOfOfficeHoursWarmer:
49
50
  enabled: true
@@ -52,6 +53,7 @@ custom:
52
53
  - schedule: cron(0/5 18-23 ? * MON-FRI *)
53
54
  - schedule: cron(0/5 * ? * SAT-SUN *)
54
55
  concurrency: 1
56
+ verbose: false
55
57
  testWarmer:
56
58
  enabled: false
57
59
  ```
@@ -70,6 +72,7 @@ The options are the same for all the warmers:
70
72
  * **timeout** How many seconds until the warmer lambda times out. (defaults to `10`)
71
73
  * **environment** Can be used to set environment variables in the warmer lambda. You can also unset variables configured at the provider by setting them to undefined. However, you should almost never have to change the default. (defaults to unset all package level environment variables. )
72
74
  * **tracing** Specify whether to enable/disable tracing at the function level. When tracing is enabled, warmer functions will use NPM to install the X-Ray client and use it to trace requests (It takes any of the values supported by serverless as `boolean`, `Active`or `PassThrough` and defaults to the provider-level setting)
75
+ * **verbose** If set to false, it disables the console.logs placed on this warmer lambda (defaults to `true`)
73
76
  * **logRetentionInDays** Set the retention time in days for the log group associated to this warmer lamba
74
77
  * **prewarm** If set to true, it warms up your lambdas right after deploying (defaults to `false`)
75
78
 
@@ -106,6 +109,7 @@ custom:
106
109
  - ./**
107
110
  timeout: 20
108
111
  tracing: true
112
+ verbose: false # Disable the logs
109
113
  logRetentionInDays: 10
110
114
  prewarm: true # Run WarmUp immediately after a deploymentlambda
111
115
  clientContext:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-plugin-warmup",
3
- "version": "7.0.2",
3
+ "version": "7.1.0",
4
4
  "description": "Keep your lambdas warm during winter.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/config.js CHANGED
@@ -41,6 +41,7 @@ function getWarmerConfig(config, defaultOpts) {
41
41
  ? config.environment
42
42
  : defaultOpts.environment,
43
43
  tracing: (config.tracing !== undefined) ? config.tracing : defaultOpts.tracing,
44
+ verbose: (config.verbose !== undefined) ? config.verbose : defaultOpts.verbose,
44
45
  logRetentionInDays: (config.logRetentionInDays !== undefined)
45
46
  ? config.logRetentionInDays
46
47
  : defaultOpts.logRetentionInDays,
@@ -151,6 +152,7 @@ function getConfigsByWarmer({ service, classes }, stage) {
151
152
  timeout: 10,
152
153
  environment: Object.keys(service.provider.environment || [])
153
154
  .reduce((obj, k) => ({ ...obj, [k]: undefined }), {}),
155
+ verbose: true,
154
156
  prewarm: false,
155
157
  });
156
158
 
package/src/index.js CHANGED
@@ -204,6 +204,7 @@ class WarmUp {
204
204
  await createWarmUpFunctionArtifact(
205
205
  warmerConfig.functions,
206
206
  warmerConfig.tracing,
207
+ warmerConfig.verbose,
207
208
  this.provider.getRegion(),
208
209
  handlerFolder,
209
210
  );
package/src/schema.js CHANGED
@@ -107,6 +107,7 @@ function extendServerlessSchema(serverless) {
107
107
  timeout: { $ref: '#/definitions/awsLambdaTimeout' },
108
108
  environment: { $ref: '#/definitions/awsLambdaEnvironment' },
109
109
  tracing: { $ref: '#/definitions/awsLambdaTracing' },
110
+ verbose: { type: 'boolean' },
110
111
  logRetentionInDays: {
111
112
  type: 'number',
112
113
  enum: [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653],
package/src/warmer.js CHANGED
@@ -94,7 +94,7 @@ function addWarmUpFunctionRoleToResources(service, stage, warmerName, warmerConf
94
94
  'lambda:InvokeFunction',
95
95
  ],
96
96
  Resource: warmerConfig.functions.map((fn) => ({
97
- 'Fn::Sub': `arn:\${AWS::Partition}:lambda:\${AWS::Region}:\${AWS::AccountId}:function:${fn.name}`,
97
+ 'Fn::Sub': `arn:\${AWS::Partition}:lambda:\${AWS::Region}:\${AWS::AccountId}:function:${fn.name}*`,
98
98
  })),
99
99
  },
100
100
  {
@@ -125,7 +125,7 @@ function addWarmUpFunctionRoleToResources(service, stage, warmerName, warmerConf
125
125
  *
126
126
  * @return {Promise}
127
127
  * */
128
- async function createWarmUpFunctionArtifact(functions, tracing, region, handlerFolder) {
128
+ async function createWarmUpFunctionArtifact(functions, tracing, verbose, region, handlerFolder) {
129
129
  const warmUpFunction = `'use strict';
130
130
 
131
131
  /** Generated by Serverless WarmUp Plugin **/
@@ -143,28 +143,32 @@ const lambda = new AWS.Lambda({
143
143
  });
144
144
  const functions = ${JSON.stringify(functions, null, ' ')};
145
145
 
146
+ function logVerbose(str) {
147
+ ${verbose ? 'console.log(str);' : ''}
148
+ }
149
+
146
150
  function getConcurrency(func, envVars) {
147
151
  const functionConcurrency = envVars[\`WARMUP_CONCURRENCY_\${func.name.toUpperCase().replace(/-/g, '_')}\`];
148
152
 
149
153
  if (functionConcurrency) {
150
154
  const concurrency = parseInt(functionConcurrency);
151
- console.log(\`Warming up function: \${func.name} with concurrency: \${concurrency} (from function-specific environment variable)\`);
155
+ logVerbose(\`Warming up function: \${func.name} with concurrency: \${concurrency} (from function-specific environment variable)\`);
152
156
  return concurrency;
153
157
  }
154
158
 
155
159
  if (envVars.WARMUP_CONCURRENCY) {
156
160
  const concurrency = parseInt(envVars.WARMUP_CONCURRENCY);
157
- console.log(\`Warming up function: \${func.name} with concurrency: \${concurrency} (from global environment variable)\`);
161
+ logVerbose(\`Warming up function: \${func.name} with concurrency: \${concurrency} (from global environment variable)\`);
158
162
  return concurrency;
159
163
  }
160
164
 
161
165
  const concurrency = parseInt(func.config.concurrency);
162
- console.log(\`Warming up function: \${func.name} with concurrency: \${concurrency}\`);
166
+ logVerbose(\`Warming up function: \${func.name} with concurrency: \${concurrency}\`);
163
167
  return concurrency;
164
168
  }
165
169
 
166
170
  module.exports.warmUp = async (event, context) => {
167
- console.log('Warm Up Start');
171
+ logVerbose('Warm Up Start');
168
172
 
169
173
  const invokes = await Promise.all(functions.map(async (func) => {
170
174
  const concurrency = getConcurrency(func, process.env);
@@ -186,15 +190,15 @@ module.exports.warmUp = async (event, context) => {
186
190
 
187
191
  try {
188
192
  await Promise.all(Array(concurrency).fill(0).map(async () => await lambda.invoke(params).promise()));
189
- console.log(\`Warm Up Invoke Success: \${func.name}\`);
193
+ logVerbose(\`Warm Up Invoke Success: \${func.name}\`);
190
194
  return true;
191
195
  } catch (e) {
192
- console.log(\`Warm Up Invoke Error: \${func.name}\`, e);
196
+ console.error(\`Warm Up Invoke Error: \${func.name}\`, e);
193
197
  return false;
194
198
  }
195
199
  }));
196
200
 
197
- console.log(\`Warm Up Finished with \${invokes.filter(r => !r).length} invoke errors\`);
201
+ logVerbose(\`Warm Up Finished with \${invokes.filter(r => !r).length} invoke errors\`);
198
202
  }`;
199
203
 
200
204
  /** Write warm up file */