serverless-plugin-warmup 7.0.2 → 7.3.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/.gitattributes +1 -0
- package/README.md +7 -1
- package/package.json +3 -3
- package/src/config.js +5 -0
- package/src/index.js +1 -0
- package/src/schema.js +2 -0
- package/src/warmer.js +15 -10
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
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
|
```
|
|
@@ -66,10 +68,12 @@ The options are the same for all the warmers:
|
|
|
66
68
|
* **vpc** The VPC and subnets in which to deploy. Can be any [Serverless VPC configuration](https://serverless.com/framework/docs/providers/aws/guide/functions#vpc-configuration) or be set to `false` in order to deploy the warmup function outside of a VPC (defaults to the vpc in the provider)
|
|
67
69
|
* **memorySize** The memory to be assigned to the warmer lambda (defaults to `128`)
|
|
68
70
|
* **events** The event that triggers the warmer lambda. Can be any [Serverless event](https://serverless.com/framework/docs/providers/aws/events/) (defaults to `- schedule: rate(5 minutes)`)
|
|
71
|
+
* **architecture** The [instruction set to use for the lambda](https://www.serverless.com/framework/docs/providers/aws/guide/functions#instruction-set-architecture) (defaults to `arm64`)
|
|
69
72
|
* **package** The package configuration. Can be any [Serverless package configuration](https://serverless.com/framework/docs/providers/aws/guide/packaging#package-configuration) (defaults to `{ individually: true, patterns: ['!**', '.warmup/${warmerName}/**'] }`)
|
|
70
73
|
* **timeout** How many seconds until the warmer lambda times out. (defaults to `10`)
|
|
71
74
|
* **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
75
|
* **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)
|
|
76
|
+
* **verbose** If set to false, it disables the console.logs placed on this warmer lambda (defaults to `true`)
|
|
73
77
|
* **logRetentionInDays** Set the retention time in days for the log group associated to this warmer lamba
|
|
74
78
|
* **prewarm** If set to true, it warms up your lambdas right after deploying (defaults to `false`)
|
|
75
79
|
|
|
@@ -106,6 +110,7 @@ custom:
|
|
|
106
110
|
- ./**
|
|
107
111
|
timeout: 20
|
|
108
112
|
tracing: true
|
|
113
|
+
verbose: false # Disable the logs
|
|
109
114
|
logRetentionInDays: 10
|
|
110
115
|
prewarm: true # Run WarmUp immediately after a deploymentlambda
|
|
111
116
|
clientContext:
|
|
@@ -251,7 +256,7 @@ The permissions can also be added to all lambdas using setting the role to `IamR
|
|
|
251
256
|
```yaml
|
|
252
257
|
provider:
|
|
253
258
|
name: aws
|
|
254
|
-
runtime:
|
|
259
|
+
runtime: nodejs16.x
|
|
255
260
|
iamRoleStatements:
|
|
256
261
|
- Effect: 'Allow'
|
|
257
262
|
Action:
|
|
@@ -263,6 +268,7 @@ custom:
|
|
|
263
268
|
default:
|
|
264
269
|
enabled: true
|
|
265
270
|
role: IamRoleLambdaExecution
|
|
271
|
+
architecture: 'arm64'
|
|
266
272
|
```
|
|
267
273
|
|
|
268
274
|
If setting `prewarm` to `true`, the deployment user used by the AWS CLI and the Serverless framework also needs permissions to invoke the warmer.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serverless-plugin-warmup",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "Keep your lambdas warm during winter.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"eslint": "^8.5.0",
|
|
35
35
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
36
36
|
"eslint-plugin-import": "^2.24.2",
|
|
37
|
-
"husky": "^
|
|
38
|
-
"jest": "^
|
|
37
|
+
"husky": "^8.0.1",
|
|
38
|
+
"jest": "^28.1.3"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/config.js
CHANGED
|
@@ -20,6 +20,9 @@ function getWarmerConfig(config, defaultOpts) {
|
|
|
20
20
|
vpc: config.vpc === false ? { securityGroupIds: [], subnetIds: [] }
|
|
21
21
|
: (config.vpc !== undefined ? config.vpc : defaultOpts.vpc),
|
|
22
22
|
events: (Array.isArray(config.events)) ? config.events : defaultOpts.events,
|
|
23
|
+
architecture: (config.architecture !== undefined)
|
|
24
|
+
? config.architecture
|
|
25
|
+
: defaultOpts.architecture,
|
|
23
26
|
package: typeof config.package === 'object'
|
|
24
27
|
? {
|
|
25
28
|
individually: (config.package.individually !== undefined)
|
|
@@ -41,6 +44,7 @@ function getWarmerConfig(config, defaultOpts) {
|
|
|
41
44
|
? config.environment
|
|
42
45
|
: defaultOpts.environment,
|
|
43
46
|
tracing: (config.tracing !== undefined) ? config.tracing : defaultOpts.tracing,
|
|
47
|
+
verbose: (config.verbose !== undefined) ? config.verbose : defaultOpts.verbose,
|
|
44
48
|
logRetentionInDays: (config.logRetentionInDays !== undefined)
|
|
45
49
|
? config.logRetentionInDays
|
|
46
50
|
: defaultOpts.logRetentionInDays,
|
|
@@ -151,6 +155,7 @@ function getConfigsByWarmer({ service, classes }, stage) {
|
|
|
151
155
|
timeout: 10,
|
|
152
156
|
environment: Object.keys(service.provider.environment || [])
|
|
153
157
|
.reduce((obj, k) => ({ ...obj, [k]: undefined }), {}),
|
|
158
|
+
verbose: true,
|
|
154
159
|
prewarm: false,
|
|
155
160
|
});
|
|
156
161
|
|
package/src/index.js
CHANGED
package/src/schema.js
CHANGED
|
@@ -94,6 +94,7 @@ function extendServerlessSchema(serverless) {
|
|
|
94
94
|
additionalProperties: false,
|
|
95
95
|
},
|
|
96
96
|
},
|
|
97
|
+
architecture: { enum: ['arm64', 'x86_64'] },
|
|
97
98
|
package: {
|
|
98
99
|
type: 'object',
|
|
99
100
|
properties: {
|
|
@@ -107,6 +108,7 @@ function extendServerlessSchema(serverless) {
|
|
|
107
108
|
timeout: { $ref: '#/definitions/awsLambdaTimeout' },
|
|
108
109
|
environment: { $ref: '#/definitions/awsLambdaEnvironment' },
|
|
109
110
|
tracing: { $ref: '#/definitions/awsLambdaTracing' },
|
|
111
|
+
verbose: { type: 'boolean' },
|
|
110
112
|
logRetentionInDays: {
|
|
111
113
|
type: 'number',
|
|
112
114
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
193
|
+
logVerbose(\`Warm Up Invoke Success: \${func.name}\`);
|
|
190
194
|
return true;
|
|
191
195
|
} catch (e) {
|
|
192
|
-
console.
|
|
196
|
+
console.error(\`Warm Up Invoke Error: \${func.name}\`, e);
|
|
193
197
|
return false;
|
|
194
198
|
}
|
|
195
199
|
}));
|
|
196
200
|
|
|
197
|
-
|
|
201
|
+
logVerbose(\`Warm Up Finished with \${invokes.filter(r => !r).length} invoke errors\`);
|
|
198
202
|
}`;
|
|
199
203
|
|
|
200
204
|
/** Write warm up file */
|
|
@@ -218,7 +222,8 @@ function addWarmUpFunctionToService(service, warmerName, warmerConfig) {
|
|
|
218
222
|
handler: warmerConfig.pathHandler.split(path.sep).join(path.posix.sep),
|
|
219
223
|
memorySize: warmerConfig.memorySize,
|
|
220
224
|
name: warmerConfig.name,
|
|
221
|
-
|
|
225
|
+
...(warmerConfig.architecture ? { architecture: warmerConfig.architecture } : {}),
|
|
226
|
+
runtime: 'nodejs16.x',
|
|
222
227
|
package: warmerConfig.package,
|
|
223
228
|
timeout: warmerConfig.timeout,
|
|
224
229
|
...(Object.keys(warmerConfig.environment).length
|