serverless-plugin-warmup 6.0.0 → 6.2.1

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/.eslintignore CHANGED
@@ -1 +1,2 @@
1
- coverage
1
+ coverage
2
+ test_integration
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  Keep your lambdas warm during winter.
10
10
 
11
11
  **Requirements:**
12
- * Serverless *v1.12.x* or higher (Recommended *v1.33.x* or higher because of [this](https://github.com/juanjoDiaz/serverless-plugin-warmup/pull/69)).
12
+ * Serverless *v2.32.x* or higher
13
13
  * AWS provider
14
14
 
15
15
  ## How it works
@@ -43,6 +43,7 @@ custom:
43
43
  events:
44
44
  - schedule: cron(0/5 8-17 ? * MON-FRI *)
45
45
  concurrency: 10
46
+ logRetentionInDays: 10
46
47
  outOfOfficeHoursWarmer:
47
48
  enabled: true
48
49
  events:
@@ -68,6 +69,7 @@ The options are the same for all the warmers:
68
69
  * **timeout** How many seconds until the warmer lambda times out. (defaults to `10`)
69
70
  * **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. )
70
71
  * **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)
72
+ * **logRetentionInDays** Set the retention time in days for the log group associated to this warmer lamba
71
73
  * **prewarm** If set to true, it warms up your lambdas right after deploying (defaults to `false`)
72
74
 
73
75
  There are also some options which can be set under `custom.warmup.<yourWarmer>` to be applied to all your lambdas or under `yourLambda.warmup.<yourWarmer>` to overridde the global configuration for that particular lambda. Keep in mind that in order to configure a warmer at the function level, it needed to be previously configured at the `custom` section or the pluging will error.
@@ -103,6 +105,7 @@ custom:
103
105
  - ./**
104
106
  timeout: 20
105
107
  tracing: true
108
+ logRetentionInDays: 10
106
109
  prewarm: true # Run WarmUp immediately after a deploymentlambda
107
110
  clientContext:
108
111
  source: my-custom-source
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-plugin-warmup",
3
- "version": "6.0.0",
3
+ "version": "6.2.1",
4
4
  "description": "Keep your lambdas warm during winter.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -31,8 +31,8 @@
31
31
  "homepage": "https://github.com/juanjoDiaz/serverless-plugin-warmup",
32
32
  "dependencies": {},
33
33
  "devDependencies": {
34
- "eslint": "^7.32.0",
35
- "eslint-config-airbnb-base": "^14.2.1",
34
+ "eslint": "^8.5.0",
35
+ "eslint-config-airbnb-base": "^15.0.0",
36
36
  "eslint-plugin-import": "^2.24.2",
37
37
  "husky": "^7.0.2",
38
38
  "jest": "^27.2.0"
package/src/config.js CHANGED
@@ -41,6 +41,9 @@ function getWarmerConfig(config, defaultOpts) {
41
41
  ? config.environment
42
42
  : defaultOpts.environment,
43
43
  tracing: (config.tracing !== undefined) ? config.tracing : defaultOpts.tracing,
44
+ logRetentionInDays: (config.logRetentionInDays !== undefined)
45
+ ? config.logRetentionInDays
46
+ : defaultOpts.logRetentionInDays,
44
47
  prewarm: (config.prewarm !== undefined) ? config.prewarm : defaultOpts.prewarm,
45
48
  };
46
49
  /* eslint-enable no-nested-ternary */
package/src/index.js CHANGED
@@ -116,7 +116,7 @@ class WarmUp {
116
116
 
117
117
  await Promise.all(foldersToClean.map(async (folderToClean) => {
118
118
  try {
119
- await fs.rmdir(
119
+ await fs.rm(
120
120
  path.join(this.serviceDir, folderToClean),
121
121
  { recursive: true },
122
122
  );
@@ -133,7 +133,7 @@ class WarmUp {
133
133
  foldersToClean.some((folder) => folder.startsWith('.warmup'))
134
134
  && (await fs.readdir(defaultDir)).length === 0
135
135
  ) {
136
- await fs.rmdir(defaultDir, { recursive: true });
136
+ await fs.rm(defaultDir, { recursive: true });
137
137
  }
138
138
  } catch (err) {
139
139
  if (err.code !== 'ENOENT') {
@@ -177,6 +177,12 @@ class WarmUp {
177
177
  return;
178
178
  }
179
179
 
180
+ // Avoid double processing due to the workaround for webpack/bundle plugins
181
+ // resetting the plugin and ignoring changes
182
+ if (this.serverless.service.functions[`warmUpPlugin${capitalize(warmerName)}`]) {
183
+ return;
184
+ }
185
+
180
186
  this.serverless.cli.log(`WarmUp: Creating warmer "${warmerName}" to warm up ${warmerConfig.functions.length} function${warmerConfig.functions.length === 1 ? '' : 's'}:`);
181
187
  warmerConfig.functions.forEach((func) => this.serverless.cli.log(` * ${func.name}`));
182
188
 
@@ -207,7 +213,7 @@ class WarmUp {
207
213
  return;
208
214
  }
209
215
 
210
- this.serverless.cli.log(`WarmUp: Prewarming up you functions using warmer "${warmerName}".`);
216
+ this.serverless.cli.log(`WarmUp: Prewarming up your functions using warmer "${warmerName}".`);
211
217
 
212
218
  try {
213
219
  const { SERVERLESS_ALIAS } = this.serverless.service.getFunction(`warmUpPlugin${capitalize(warmerName)}`).environment || {};
package/src/schema.js CHANGED
@@ -5,7 +5,7 @@ function extendServerlessSchema(serverless) {
5
5
  // Most of these are taken from
6
6
  // https://github.com/serverless/serverless/blob/master/lib/configSchema.js
7
7
  // https://github.com/serverless/serverless/blob/master/lib/plugins/aws/provider.js
8
- // https://github.com/serverless/serverless/blob/master/lib/plugins/aws/package/compile/events/schedule/index.js
8
+ // https://github.com/serverless/serverless/blob/master/lib/plugins/aws/package/compile/events/schedule.js
9
9
 
10
10
  const rateSyntax = '^rate\\((?:1 (?:minute|hour|day)|(?:1\\d+|[2-9]\\d*) (?:minute|hour|day)s)\\)$';
11
11
  const cronSyntax = '^cron\\(\\S+ \\S+ \\S+ \\S+ \\S+ \\S+\\)$';
@@ -27,59 +27,71 @@ function extendServerlessSchema(serverless) {
27
27
  type: 'array',
28
28
  items: {
29
29
  type: 'object',
30
- anyOf: [
31
- { type: 'string', pattern: scheduleSyntax },
32
- {
33
- type: 'object',
34
- properties: {
35
- rate: { type: 'string', pattern: scheduleSyntax },
36
- enabled: { type: 'boolean' },
37
- alias: { type: 'string' },
38
- name: {
39
- type: 'string', minLength: 1, maxLength: 64, pattern: '[\\.\\-_A-Za-z0-9]+',
30
+ properties: {
31
+ schedule: {
32
+ anyOf: [
33
+ { type: 'string', pattern: scheduleSyntax },
34
+ {
35
+ type: 'object',
36
+ properties: {
37
+ rate: {
38
+ type: 'array',
39
+ minItems: 1,
40
+ items: {
41
+ type: 'string',
42
+ pattern: scheduleSyntax,
43
+ },
44
+ },
45
+ enabled: { type: 'boolean' },
46
+ name: {
47
+ type: 'string', minLength: 1, maxLength: 64, pattern: '[\\.\\-_A-Za-z0-9]+',
48
+ },
49
+ description: { type: 'string', maxLength: 512 },
50
+ input: {
51
+ anyOf: [
52
+ { type: 'string', maxLength: 8192 },
53
+ {
54
+ type: 'object',
55
+ oneOf: [
56
+ {
57
+ properties: {
58
+ body: { type: 'string', maxLength: 8192 },
59
+ },
60
+ required: ['body'],
61
+ additionalProperties: false,
62
+ },
63
+ {
64
+ not: {
65
+ required: ['body'],
66
+ },
67
+ },
68
+ ],
69
+ },
70
+ ],
71
+ },
72
+ inputPath: { type: 'string', maxLength: 256 },
73
+ inputTransformer: {
74
+ type: 'object',
75
+ properties: {
76
+ inputTemplate: {
77
+ type: 'string',
78
+ minLength: 1,
79
+ maxLength: 8192,
80
+ },
81
+ inputPathsMap: { type: 'object' },
82
+ },
83
+ required: ['inputTemplate'],
84
+ additionalProperties: false,
85
+ },
86
+ },
87
+ required: ['rate'],
88
+ additionalProperties: false,
40
89
  },
41
- description: { type: 'string', maxLength: 512 },
42
- // input: {
43
- // anyOf: [
44
- // { type: 'string', maxLength: 8192 },
45
- // {
46
- // type: 'object',
47
- // oneOf: [
48
- // {
49
- // properties: {
50
- // body: { type: 'string', maxLength: 8192 },
51
- // },
52
- // required: ['body'],
53
- // additionalProperties: false,
54
- // },
55
- // {
56
- // not: {
57
- // required: ['body'],
58
- // },
59
- // },
60
- // ],
61
- // },
62
- // ],
63
- // },
64
- // inputPath: { type: 'string', maxLength: 256 },
65
- // inputTransformer: {
66
- // type: 'object',
67
- // properties: {
68
- // inputTemplate: {
69
- // type: 'string',
70
- // minLength: 1,
71
- // maxLength: 8192,
72
- // },
73
- // inputPathsMap: { type: 'object' },
74
- // },
75
- // required: ['inputTemplate'],
76
- // additionalProperties: false,
77
- // },
78
- },
79
- required: ['rate'],
80
- additionalProperties: false,
90
+ ],
81
91
  },
82
- ],
92
+ },
93
+ required: ['schedule'],
94
+ additionalProperties: false,
83
95
  },
84
96
  },
85
97
  package: {
@@ -95,6 +107,10 @@ function extendServerlessSchema(serverless) {
95
107
  timeout: { $ref: '#/definitions/awsLambdaTimeout' },
96
108
  environment: { $ref: '#/definitions/awsLambdaEnvironment' },
97
109
  tracing: { $ref: '#/definitions/awsLambdaTracing' },
110
+ logRetentionInDays: {
111
+ type: 'number',
112
+ enum: [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653],
113
+ },
98
114
  prewarm: { type: 'boolean' },
99
115
  };
100
116
 
@@ -123,10 +139,13 @@ function extendServerlessSchema(serverless) {
123
139
  serverless.configSchemaHandler.defineCustomProperties({
124
140
  properties: {
125
141
  warmup: {
126
- '.*': {
127
- type: 'object',
128
- properties: { ...globalConfigSchemaProperties, ...functionConfigSchemaProperties },
129
- additionalProperties: false,
142
+ type: 'object',
143
+ patternProperties: {
144
+ '.*': {
145
+ type: 'object',
146
+ properties: { ...globalConfigSchemaProperties, ...functionConfigSchemaProperties },
147
+ additionalProperties: false,
148
+ },
130
149
  },
131
150
  },
132
151
  },
@@ -138,10 +157,13 @@ function extendServerlessSchema(serverless) {
138
157
  type: 'object',
139
158
  properties: {
140
159
  warmup: {
141
- '.*': {
142
- type: 'object',
143
- properties: { functionConfigSchemaProperties },
144
- additionalProperties: false,
160
+ type: 'object',
161
+ patternProperties: {
162
+ '.*': {
163
+ type: 'object',
164
+ properties: functionConfigSchemaProperties,
165
+ additionalProperties: false,
166
+ },
145
167
  },
146
168
  },
147
169
  },
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
  {
@@ -225,9 +225,13 @@ function addWarmUpFunctionToService(service, warmerName, warmerConfig) {
225
225
  ? { environment: warmerConfig.environment }
226
226
  : {}),
227
227
  ...(warmerConfig.tracing !== undefined ? { tracing: warmerConfig.tracing } : {}),
228
+ ...(warmerConfig.logRetentionInDays !== undefined
229
+ ? { logRetentionInDays: warmerConfig.logRetentionInDays }
230
+ : {}),
228
231
  ...(warmerConfig.role ? { role: warmerConfig.role } : {}),
229
232
  ...(warmerConfig.tags ? { tags: warmerConfig.tags } : {}),
230
233
  ...(warmerConfig.vpc ? { vpc: warmerConfig.vpc } : {}),
234
+ layers: [],
231
235
  };
232
236
  }
233
237