serverless-plugin-warmup 8.2.1 → 8.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/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  Keep your lambdas warm during winter.
10
10
 
11
11
  **Requirements:**
12
- * Node *v14.x* or higher
12
+ * Node *v18.x* or higher
13
13
  * Serverless *v3.8* or higher
14
14
  * AWS provider
15
15
 
@@ -258,7 +258,7 @@ The permissions can also be added to all lambdas using setting the role to `IamR
258
258
  ```yaml
259
259
  provider:
260
260
  name: aws
261
- runtime: nodejs18.x
261
+ runtime: nodejs20.x
262
262
  iamRoleStatements:
263
263
  - Effect: 'Allow'
264
264
  Action:
@@ -585,13 +585,13 @@ You can check the Lambda [pricing](https://aws.amazon.com/lambda/pricing/) and C
585
585
 
586
586
  #### Example
587
587
 
588
- If you have a single warmer and want to warm 10 functions, each with `memorySize = 1024` and `duration = 10`, using the default settings (and we ignore the free tier):
588
+ If you have a single warmer and want to warm 10 functions, each with `memorySize = 1024` and `duration = 10`, using the default settings ($0.0000166667 for every GB-second) and ignoring the free tier:
589
589
 
590
- * WarmUp: runs 8640 times per month = $0.18
591
- * 10 warm lambdas: each invoked 8640 times per month = $14.4
592
- * Total = $14.58
590
+ * WarmUp: runs 8640 times per month = $0.0
591
+ * 10 warm lambdas: each invoked 8640 times per month = $0.3
592
+ * Total = $0.3
593
593
 
594
- CloudWatch costs are not in this example because they are very low.
594
+ CloudWatch costs are not consdiered in this example.
595
595
 
596
596
  ## Contribute
597
597
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-plugin-warmup",
3
- "version": "8.2.1",
3
+ "version": "8.3.0",
4
4
  "description": "Keep your lambdas warm during winter.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/config.js CHANGED
@@ -167,7 +167,7 @@ function getConfigsByWarmer({ service, classes }, stage) {
167
167
  concurrency: 1,
168
168
  };
169
169
 
170
- const configsByWarmer = Object.entries(service.custom ? service.custom.warmup : {})
170
+ const configsByWarmer = Object.entries((service.custom && service.custom.warmup) || {})
171
171
  .reduce((warmers, [warmerName, warmerConfig]) => ({
172
172
  ...warmers,
173
173
  [warmerName]: {
package/src/schema.js CHANGED
@@ -122,6 +122,7 @@ function extendServerlessSchema(serverless) {
122
122
  { type: 'array', items: { type: 'string' } },
123
123
  ],
124
124
  },
125
+ alias: { type: 'string' },
125
126
  clientContext: {
126
127
  anyOf: [
127
128
  { const: false }, // to skip it
package/src/warmer.js CHANGED
@@ -126,18 +126,20 @@ function addWarmUpFunctionRoleToResources(service, stage, warmerName, warmerConf
126
126
  * @return {Promise}
127
127
  * */
128
128
  async function createWarmUpFunctionArtifact(functions, tracing, verbose, region, handlerFolder) {
129
- const warmUpFunction = `'use strict';
130
-
129
+ const warmUpFunction = `
131
130
  /** Generated by Serverless WarmUp Plugin **/
132
131
 
133
- ${tracing
134
- ? `const AWSXRay = require('aws-xray-sdk-core');
135
- const AWS = AWSXRay.captureAWS(require('@aws-sdk/client-lambda'));`
136
- : 'const AWS = require(\'@aws-sdk/client-lambda\')'};
137
- const lambda = new AWS.Lambda({
132
+ import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda';
133
+
134
+ const uninstrumentedLambdaClient = new LambdaClient({
138
135
  apiVersion: '2015-03-31',
139
136
  region: '${region}'
140
137
  });
138
+
139
+ ${tracing
140
+ ? 'const lambdaClient = AWSXRay.captureAWSv3Client(uninstrumentedLambdaClient);'
141
+ : 'const lambdaClient = uninstrumentedLambdaClient;'}
142
+
141
143
  const functions = ${JSON.stringify(functions, null, ' ')};
142
144
 
143
145
  function logVerbose(str) {
@@ -164,7 +166,7 @@ function getConcurrency(func, envVars) {
164
166
  return concurrency;
165
167
  }
166
168
 
167
- module.exports.warmUp = async (event, context) => {
169
+ export const warmUp = async (event, context) => {
168
170
  logVerbose('Warm Up Start');
169
171
 
170
172
  const invokes = await Promise.all(functions.map(async (func) => {
@@ -174,7 +176,7 @@ module.exports.warmUp = async (event, context) => {
174
176
  ? func.config.clientContext
175
177
  : func.config.payload;
176
178
 
177
- const params = {
179
+ const invokeCommand = new InvokeCommand({
178
180
  ClientContext: clientContext
179
181
  ? Buffer.from(\`{"custom":\${clientContext}}\`).toString('base64')
180
182
  : undefined,
@@ -183,10 +185,10 @@ module.exports.warmUp = async (event, context) => {
183
185
  LogType: 'None',
184
186
  Qualifier: func.config.alias || process.env.SERVERLESS_ALIAS,
185
187
  Payload: func.config.payload
186
- };
188
+ });
187
189
 
188
190
  try {
189
- await Promise.all(Array(concurrency).fill(0).map(async () => await lambda.invoke(params)));
191
+ await Promise.all(Array(concurrency).fill(0).map(async () => await lambdaClient.send(invokeCommand)));
190
192
  logVerbose(\`Warm Up Invoke Success: \${func.name}\`);
191
193
  return true;
192
194
  } catch (e) {
@@ -200,7 +202,7 @@ module.exports.warmUp = async (event, context) => {
200
202
 
201
203
  /** Write warm up file */
202
204
  await fs.mkdir(handlerFolder, { recursive: true });
203
- await fs.writeFile(path.join(handlerFolder, 'index.js'), warmUpFunction);
205
+ await fs.writeFile(path.join(handlerFolder, 'index.mjs'), warmUpFunction);
204
206
 
205
207
  if (tracing) {
206
208
  await execAsync('npm init -y', { cwd: handlerFolder });
@@ -220,7 +222,7 @@ function addWarmUpFunctionToService(service, warmerName, warmerConfig) {
220
222
  memorySize: warmerConfig.memorySize,
221
223
  name: warmerConfig.name,
222
224
  ...(warmerConfig.architecture ? { architecture: warmerConfig.architecture } : {}),
223
- runtime: 'nodejs18.x',
225
+ runtime: 'nodejs20.x',
224
226
  package: warmerConfig.package,
225
227
  timeout: warmerConfig.timeout,
226
228
  ...(Object.keys(warmerConfig.environment).length