serverless-plugin-warmup 8.2.0 → 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 +7 -7
- package/package.json +1 -1
- package/src/config.js +1 -1
- package/src/schema.js +1 -0
- package/src/warmer.js +16 -17
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
Keep your lambdas warm during winter.
|
|
10
10
|
|
|
11
11
|
**Requirements:**
|
|
12
|
-
* Node *
|
|
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:
|
|
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
|
|
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.
|
|
591
|
-
* 10 warm lambdas: each invoked 8640 times per month = $
|
|
592
|
-
* Total = $
|
|
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
|
|
594
|
+
CloudWatch costs are not consdiered in this example.
|
|
595
595
|
|
|
596
596
|
## Contribute
|
|
597
597
|
|
package/package.json
CHANGED
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
|
|
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
package/src/warmer.js
CHANGED
|
@@ -126,21 +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 = `
|
|
130
|
-
|
|
129
|
+
const warmUpFunction = `
|
|
131
130
|
/** Generated by Serverless WarmUp Plugin **/
|
|
132
131
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
: 'const AWS = require(\'aws-sdk\')'};
|
|
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
|
-
region: '${region}'
|
|
140
|
-
httpOptions: {
|
|
141
|
-
connectTimeout: 1000, // 1 second
|
|
142
|
-
},
|
|
136
|
+
region: '${region}'
|
|
143
137
|
});
|
|
138
|
+
|
|
139
|
+
${tracing
|
|
140
|
+
? 'const lambdaClient = AWSXRay.captureAWSv3Client(uninstrumentedLambdaClient);'
|
|
141
|
+
: 'const lambdaClient = uninstrumentedLambdaClient;'}
|
|
142
|
+
|
|
144
143
|
const functions = ${JSON.stringify(functions, null, ' ')};
|
|
145
144
|
|
|
146
145
|
function logVerbose(str) {
|
|
@@ -167,7 +166,7 @@ function getConcurrency(func, envVars) {
|
|
|
167
166
|
return concurrency;
|
|
168
167
|
}
|
|
169
168
|
|
|
170
|
-
|
|
169
|
+
export const warmUp = async (event, context) => {
|
|
171
170
|
logVerbose('Warm Up Start');
|
|
172
171
|
|
|
173
172
|
const invokes = await Promise.all(functions.map(async (func) => {
|
|
@@ -177,7 +176,7 @@ module.exports.warmUp = async (event, context) => {
|
|
|
177
176
|
? func.config.clientContext
|
|
178
177
|
: func.config.payload;
|
|
179
178
|
|
|
180
|
-
const
|
|
179
|
+
const invokeCommand = new InvokeCommand({
|
|
181
180
|
ClientContext: clientContext
|
|
182
181
|
? Buffer.from(\`{"custom":\${clientContext}}\`).toString('base64')
|
|
183
182
|
: undefined,
|
|
@@ -186,10 +185,10 @@ module.exports.warmUp = async (event, context) => {
|
|
|
186
185
|
LogType: 'None',
|
|
187
186
|
Qualifier: func.config.alias || process.env.SERVERLESS_ALIAS,
|
|
188
187
|
Payload: func.config.payload
|
|
189
|
-
};
|
|
188
|
+
});
|
|
190
189
|
|
|
191
190
|
try {
|
|
192
|
-
await Promise.all(Array(concurrency).fill(0).map(async () => await
|
|
191
|
+
await Promise.all(Array(concurrency).fill(0).map(async () => await lambdaClient.send(invokeCommand)));
|
|
193
192
|
logVerbose(\`Warm Up Invoke Success: \${func.name}\`);
|
|
194
193
|
return true;
|
|
195
194
|
} catch (e) {
|
|
@@ -203,7 +202,7 @@ module.exports.warmUp = async (event, context) => {
|
|
|
203
202
|
|
|
204
203
|
/** Write warm up file */
|
|
205
204
|
await fs.mkdir(handlerFolder, { recursive: true });
|
|
206
|
-
await fs.writeFile(path.join(handlerFolder, 'index.
|
|
205
|
+
await fs.writeFile(path.join(handlerFolder, 'index.mjs'), warmUpFunction);
|
|
207
206
|
|
|
208
207
|
if (tracing) {
|
|
209
208
|
await execAsync('npm init -y', { cwd: handlerFolder });
|
|
@@ -223,7 +222,7 @@ function addWarmUpFunctionToService(service, warmerName, warmerConfig) {
|
|
|
223
222
|
memorySize: warmerConfig.memorySize,
|
|
224
223
|
name: warmerConfig.name,
|
|
225
224
|
...(warmerConfig.architecture ? { architecture: warmerConfig.architecture } : {}),
|
|
226
|
-
runtime: '
|
|
225
|
+
runtime: 'nodejs20.x',
|
|
227
226
|
package: warmerConfig.package,
|
|
228
227
|
timeout: warmerConfig.timeout,
|
|
229
228
|
...(Object.keys(warmerConfig.environment).length
|