serverless-plugin-warmup 8.3.0 → 8.4.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 +3 -3
- package/biome.json +47 -0
- package/package.json +36 -38
- package/src/config.js +159 -147
- package/src/index.js +245 -225
- package/src/schema.js +178 -163
- package/src/utils.js +1 -1
- package/src/warmer.js +130 -142
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -9
package/src/schema.js
CHANGED
|
@@ -2,176 +2,191 @@
|
|
|
2
2
|
* @description Define the additions to the serverless schema by this plugin.
|
|
3
3
|
* */
|
|
4
4
|
function extendServerlessSchema(serverless) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
// Most of these are taken from
|
|
6
|
+
// https://github.com/serverless/serverless/blob/master/lib/configSchema.js
|
|
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.js
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const rateSyntax =
|
|
11
|
+
'^rate\\((?:1 (?:minute|hour|day)|(?:1\\d+|[2-9]\\d*) (?:minute|hour|day)s)\\)$';
|
|
12
|
+
const cronSyntax = '^cron\\(\\S+ \\S+ \\S+ \\S+ \\S+ \\S+\\)$';
|
|
13
|
+
const scheduleSyntax = `${rateSyntax}|${cronSyntax}`;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
cleanFolder: { type: 'boolean' },
|
|
17
|
-
name: { type: 'string' },
|
|
18
|
-
roleName: { type: 'string' },
|
|
19
|
-
role: { $ref: '#/definitions/awsLambdaRole' },
|
|
20
|
-
tags: { $ref: '#/definitions/awsResourceTags' },
|
|
21
|
-
vpc: {
|
|
22
|
-
anyOf: [
|
|
23
|
-
{ const: false }, // to deploy outside of the VPC
|
|
24
|
-
{ $ref: '#/definitions/awsLambdaVpcConfig' },
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
events: {
|
|
28
|
-
type: 'array',
|
|
29
|
-
items: {
|
|
30
|
-
type: 'object',
|
|
31
|
-
properties: {
|
|
32
|
-
schedule: {
|
|
33
|
-
anyOf: [
|
|
34
|
-
{ type: 'string', pattern: scheduleSyntax },
|
|
35
|
-
{
|
|
36
|
-
type: 'object',
|
|
37
|
-
properties: {
|
|
38
|
-
rate: {
|
|
39
|
-
type: 'array',
|
|
40
|
-
minItems: 1,
|
|
41
|
-
items: {
|
|
42
|
-
type: 'string',
|
|
43
|
-
pattern: scheduleSyntax,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
enabled: { type: 'boolean' },
|
|
47
|
-
name: {
|
|
48
|
-
type: 'string', minLength: 1, maxLength: 64, pattern: '[\\.\\-_A-Za-z0-9]+',
|
|
49
|
-
},
|
|
50
|
-
description: { type: 'string', maxLength: 512 },
|
|
51
|
-
input: {
|
|
52
|
-
anyOf: [
|
|
53
|
-
{ type: 'string', maxLength: 8192 },
|
|
54
|
-
{
|
|
55
|
-
type: 'object',
|
|
56
|
-
oneOf: [
|
|
57
|
-
{
|
|
58
|
-
properties: {
|
|
59
|
-
body: { type: 'string', maxLength: 8192 },
|
|
60
|
-
},
|
|
61
|
-
required: ['body'],
|
|
62
|
-
additionalProperties: false,
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
not: {
|
|
66
|
-
required: ['body'],
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
},
|
|
73
|
-
inputPath: { type: 'string', maxLength: 256 },
|
|
74
|
-
inputTransformer: {
|
|
75
|
-
type: 'object',
|
|
76
|
-
properties: {
|
|
77
|
-
inputTemplate: {
|
|
78
|
-
type: 'string',
|
|
79
|
-
minLength: 1,
|
|
80
|
-
maxLength: 8192,
|
|
81
|
-
},
|
|
82
|
-
inputPathsMap: { type: 'object' },
|
|
83
|
-
},
|
|
84
|
-
required: ['inputTemplate'],
|
|
85
|
-
additionalProperties: false,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
required: ['rate'],
|
|
89
|
-
additionalProperties: false,
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
required: ['schedule'],
|
|
95
|
-
additionalProperties: false,
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
architecture: { enum: ['arm64', 'x86_64'] },
|
|
99
|
-
package: {
|
|
100
|
-
type: 'object',
|
|
101
|
-
properties: {
|
|
102
|
-
artifact: { type: 'string' },
|
|
103
|
-
patterns: { type: 'array', items: { type: 'string' } },
|
|
104
|
-
individually: { type: 'boolean' },
|
|
105
|
-
},
|
|
106
|
-
additionalProperties: false,
|
|
107
|
-
},
|
|
108
|
-
memorySize: { $ref: '#/definitions/awsLambdaMemorySize' },
|
|
109
|
-
timeout: { $ref: '#/definitions/awsLambdaTimeout' },
|
|
110
|
-
environment: { $ref: '#/definitions/awsLambdaEnvironment' },
|
|
111
|
-
tracing: { $ref: '#/definitions/awsLambdaTracing' },
|
|
112
|
-
verbose: { type: 'boolean' },
|
|
113
|
-
logRetentionInDays: { $ref: '#/definitions/awsLogRetentionInDays' },
|
|
114
|
-
prewarm: { type: 'boolean' },
|
|
115
|
-
};
|
|
15
|
+
const METHOD_SCHEDULER = 'scheduler';
|
|
16
|
+
const METHOD_EVENT_BUS = 'eventBus';
|
|
116
17
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
18
|
+
const globalConfigSchemaProperties = {
|
|
19
|
+
folderName: { type: 'string' },
|
|
20
|
+
cleanFolder: { type: 'boolean' },
|
|
21
|
+
name: { type: 'string' },
|
|
22
|
+
roleName: { type: 'string' },
|
|
23
|
+
role: { $ref: '#/definitions/awsLambdaRole' },
|
|
24
|
+
tags: { $ref: '#/definitions/awsResourceTags' },
|
|
25
|
+
vpc: {
|
|
26
|
+
anyOf: [
|
|
27
|
+
{ const: false }, // to deploy outside of the VPC
|
|
28
|
+
{ $ref: '#/definitions/awsLambdaVpcConfig' },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
events: {
|
|
32
|
+
type: 'array',
|
|
33
|
+
items: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
schedule: {
|
|
37
|
+
anyOf: [
|
|
38
|
+
{ type: 'string', pattern: scheduleSyntax },
|
|
39
|
+
{
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
rate: {
|
|
43
|
+
type: 'array',
|
|
44
|
+
minItems: 1,
|
|
45
|
+
items: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
pattern: scheduleSyntax,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
enabled: { type: 'boolean' },
|
|
51
|
+
name: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
minLength: 1,
|
|
54
|
+
maxLength: 64,
|
|
55
|
+
pattern: '[\\.\\-_A-Za-z0-9]+',
|
|
56
|
+
},
|
|
57
|
+
description: { type: 'string', maxLength: 512 },
|
|
58
|
+
input: {
|
|
59
|
+
anyOf: [
|
|
60
|
+
{ type: 'string', maxLength: 8192 },
|
|
61
|
+
{
|
|
62
|
+
type: 'object',
|
|
63
|
+
oneOf: [
|
|
64
|
+
{
|
|
65
|
+
properties: {
|
|
66
|
+
body: { type: 'string', maxLength: 8192 },
|
|
67
|
+
},
|
|
68
|
+
required: ['body'],
|
|
69
|
+
additionalProperties: false,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
not: {
|
|
73
|
+
required: ['body'],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
inputPath: { type: 'string', maxLength: 256 },
|
|
81
|
+
inputTransformer: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
inputTemplate: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
minLength: 1,
|
|
87
|
+
maxLength: 8192,
|
|
88
|
+
},
|
|
89
|
+
inputPathsMap: { type: 'object' },
|
|
90
|
+
},
|
|
91
|
+
required: ['inputTemplate'],
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
},
|
|
94
|
+
method: {
|
|
95
|
+
type: 'string',
|
|
96
|
+
enum: [METHOD_EVENT_BUS, METHOD_SCHEDULER],
|
|
97
|
+
},
|
|
98
|
+
timezone: {
|
|
99
|
+
type: 'string',
|
|
100
|
+
pattern: '[\\w\\-\\/]+',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
required: ['rate'],
|
|
104
|
+
additionalProperties: false,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
required: ['schedule'],
|
|
110
|
+
additionalProperties: false,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
architecture: { enum: ['arm64', 'x86_64'] },
|
|
114
|
+
package: {
|
|
115
|
+
type: 'object',
|
|
116
|
+
properties: {
|
|
117
|
+
artifact: { type: 'string' },
|
|
118
|
+
patterns: { type: 'array', items: { type: 'string' } },
|
|
119
|
+
individually: { type: 'boolean' },
|
|
120
|
+
},
|
|
121
|
+
additionalProperties: false,
|
|
122
|
+
},
|
|
123
|
+
memorySize: { $ref: '#/definitions/awsLambdaMemorySize' },
|
|
124
|
+
timeout: { $ref: '#/definitions/awsLambdaTimeout' },
|
|
125
|
+
environment: { $ref: '#/definitions/awsLambdaEnvironment' },
|
|
126
|
+
tracing: { $ref: '#/definitions/awsLambdaTracing' },
|
|
127
|
+
verbose: { type: 'boolean' },
|
|
128
|
+
logRetentionInDays: { $ref: '#/definitions/awsLogRetentionInDays' },
|
|
129
|
+
prewarm: { type: 'boolean' },
|
|
130
|
+
};
|
|
136
131
|
|
|
137
|
-
|
|
132
|
+
const functionConfigSchemaProperties = {
|
|
133
|
+
enabled: {
|
|
134
|
+
anyOf: [
|
|
135
|
+
{ type: 'boolean' },
|
|
136
|
+
{ type: 'string' },
|
|
137
|
+
{ type: 'array', items: { type: 'string' } },
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
alias: { type: 'string' },
|
|
141
|
+
clientContext: {
|
|
142
|
+
anyOf: [
|
|
143
|
+
{ const: false }, // to skip it
|
|
144
|
+
{ type: 'object' }, // any
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
payload: { type: 'object' }, // any
|
|
148
|
+
payloadRaw: { type: 'boolean' },
|
|
149
|
+
concurrency: { type: 'integer' },
|
|
150
|
+
};
|
|
138
151
|
|
|
139
|
-
|
|
140
|
-
serverless.configSchemaHandler.defineCustomProperties({
|
|
141
|
-
properties: {
|
|
142
|
-
warmup: {
|
|
143
|
-
type: 'object',
|
|
144
|
-
patternProperties: {
|
|
145
|
-
'.*': {
|
|
146
|
-
type: 'object',
|
|
147
|
-
properties: { ...globalConfigSchemaProperties, ...functionConfigSchemaProperties },
|
|
148
|
-
additionalProperties: false,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
}
|
|
152
|
+
if (!serverless.configSchemaHandler) return;
|
|
155
153
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
154
|
+
if (typeof serverless.configSchemaHandler.defineCustomProperties === 'function') {
|
|
155
|
+
serverless.configSchemaHandler.defineCustomProperties({
|
|
156
|
+
properties: {
|
|
157
|
+
warmup: {
|
|
158
|
+
type: 'object',
|
|
159
|
+
patternProperties: {
|
|
160
|
+
'.*': {
|
|
161
|
+
type: 'object',
|
|
162
|
+
properties: { ...globalConfigSchemaProperties, ...functionConfigSchemaProperties },
|
|
163
|
+
additionalProperties: false,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (typeof serverless.configSchemaHandler.defineFunctionProperties === 'function') {
|
|
172
|
+
serverless.configSchemaHandler.defineFunctionProperties('aws', {
|
|
173
|
+
type: 'object',
|
|
174
|
+
properties: {
|
|
175
|
+
warmup: {
|
|
176
|
+
type: 'object',
|
|
177
|
+
patternProperties: {
|
|
178
|
+
'.*': {
|
|
179
|
+
type: 'object',
|
|
180
|
+
properties: functionConfigSchemaProperties,
|
|
181
|
+
additionalProperties: false,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
}
|
|
173
188
|
}
|
|
174
189
|
|
|
175
190
|
module.exports = {
|
|
176
|
-
|
|
191
|
+
extendServerlessSchema,
|
|
177
192
|
};
|
package/src/utils.js
CHANGED
package/src/warmer.js
CHANGED
|
@@ -10,109 +10,92 @@ const execAsync = util.promisify(exec);
|
|
|
10
10
|
* @description Add warmer role to service
|
|
11
11
|
* */
|
|
12
12
|
function addWarmUpFunctionRoleToResources(service, stage, warmerName, warmerConfig) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
Effect: 'Allow',
|
|
102
|
-
Action: [
|
|
103
|
-
'ec2:CreateNetworkInterface',
|
|
104
|
-
'ec2:DescribeNetworkInterfaces',
|
|
105
|
-
'ec2:DetachNetworkInterface',
|
|
106
|
-
'ec2:DeleteNetworkInterface',
|
|
107
|
-
],
|
|
108
|
-
Resource: '*',
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
},
|
|
115
|
-
};
|
|
13
|
+
// eslint-disable-next-line no-param-reassign
|
|
14
|
+
warmerConfig.role = `WarmUpPlugin${capitalize(warmerName)}Role`;
|
|
15
|
+
if (typeof service.resources !== 'object') {
|
|
16
|
+
// eslint-disable-next-line no-param-reassign
|
|
17
|
+
service.resources = {};
|
|
18
|
+
}
|
|
19
|
+
if (typeof service.resources.Resources !== 'object') {
|
|
20
|
+
// eslint-disable-next-line no-param-reassign
|
|
21
|
+
service.resources.Resources = {};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line no-param-reassign
|
|
25
|
+
service.resources.Resources[warmerConfig.role] = {
|
|
26
|
+
Type: 'AWS::IAM::Role',
|
|
27
|
+
Properties: {
|
|
28
|
+
Path: '/',
|
|
29
|
+
RoleName: warmerConfig.roleName || {
|
|
30
|
+
'Fn::Join': [
|
|
31
|
+
'-',
|
|
32
|
+
[service.service, stage, { Ref: 'AWS::Region' }, warmerName.toLowerCase(), 'role'],
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
AssumeRolePolicyDocument: {
|
|
36
|
+
Version: '2012-10-17',
|
|
37
|
+
Statement: [
|
|
38
|
+
{
|
|
39
|
+
Effect: 'Allow',
|
|
40
|
+
Principal: {
|
|
41
|
+
Service: ['lambda.amazonaws.com'],
|
|
42
|
+
},
|
|
43
|
+
Action: 'sts:AssumeRole',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
Policies: [
|
|
48
|
+
{
|
|
49
|
+
PolicyName: {
|
|
50
|
+
'Fn::Join': [
|
|
51
|
+
'-',
|
|
52
|
+
[service.service, stage, 'warmer', warmerName.toLowerCase(), 'policy'],
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
PolicyDocument: {
|
|
56
|
+
Version: '2012-10-17',
|
|
57
|
+
Statement: [
|
|
58
|
+
{
|
|
59
|
+
Effect: 'Allow',
|
|
60
|
+
Action: ['logs:CreateLogGroup', 'logs:CreateLogStream'],
|
|
61
|
+
Resource: [
|
|
62
|
+
{
|
|
63
|
+
'Fn::Sub': `arn:\${AWS::Partition}:logs:\${AWS::Region}:\${AWS::AccountId}:log-group:/aws/lambda/${warmerConfig.name}:*`,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
Effect: 'Allow',
|
|
69
|
+
Action: ['logs:PutLogEvents'],
|
|
70
|
+
Resource: [
|
|
71
|
+
{
|
|
72
|
+
'Fn::Sub': `arn:\${AWS::Partition}:logs:\${AWS::Region}:\${AWS::AccountId}:log-group:/aws/lambda/${warmerConfig.name}:*:*`,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
Effect: 'Allow',
|
|
78
|
+
Action: ['lambda:InvokeFunction'],
|
|
79
|
+
Resource: warmerConfig.functions.map((fn) => ({
|
|
80
|
+
'Fn::Sub': `arn:\${AWS::Partition}:lambda:\${AWS::Region}:\${AWS::AccountId}:function:${fn.name}*`,
|
|
81
|
+
})),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
Effect: 'Allow',
|
|
85
|
+
Action: [
|
|
86
|
+
'ec2:CreateNetworkInterface',
|
|
87
|
+
'ec2:DescribeNetworkInterfaces',
|
|
88
|
+
'ec2:DetachNetworkInterface',
|
|
89
|
+
'ec2:DeleteNetworkInterface',
|
|
90
|
+
],
|
|
91
|
+
Resource: '*',
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
};
|
|
116
99
|
}
|
|
117
100
|
|
|
118
101
|
/**
|
|
@@ -126,19 +109,24 @@ function addWarmUpFunctionRoleToResources(service, stage, warmerName, warmerConf
|
|
|
126
109
|
* @return {Promise}
|
|
127
110
|
* */
|
|
128
111
|
async function createWarmUpFunctionArtifact(functions, tracing, verbose, region, handlerFolder) {
|
|
129
|
-
|
|
112
|
+
const warmUpFunction = `
|
|
130
113
|
/** Generated by Serverless WarmUp Plugin **/
|
|
131
114
|
|
|
132
115
|
import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda';
|
|
116
|
+
import { NodeHttpHandler } from '@smithy/node-http-handler';
|
|
133
117
|
|
|
134
118
|
const uninstrumentedLambdaClient = new LambdaClient({
|
|
135
119
|
apiVersion: '2015-03-31',
|
|
136
|
-
region: '${region}'
|
|
120
|
+
region: '${region}',
|
|
121
|
+
requestHandler: new NodeHttpHandler({ connectionTimeout: 1000 }),
|
|
137
122
|
});
|
|
138
123
|
|
|
139
|
-
${
|
|
140
|
-
|
|
141
|
-
|
|
124
|
+
${
|
|
125
|
+
tracing
|
|
126
|
+
? `import * as AWSXRay from 'aws-xray-sdk';
|
|
127
|
+
const lambdaClient = AWSXRay.captureAWSv3Client(uninstrumentedLambdaClient);`
|
|
128
|
+
: 'const lambdaClient = uninstrumentedLambdaClient;'
|
|
129
|
+
}
|
|
142
130
|
|
|
143
131
|
const functions = ${JSON.stringify(functions, null, ' ')};
|
|
144
132
|
|
|
@@ -200,48 +188,48 @@ export const warmUp = async (event, context) => {
|
|
|
200
188
|
logVerbose(\`Warm Up Finished with \${invokes.filter(r => !r).length} invoke errors\`);
|
|
201
189
|
}`;
|
|
202
190
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
191
|
+
/** Write warm up file */
|
|
192
|
+
await fs.mkdir(handlerFolder, { recursive: true });
|
|
193
|
+
await fs.writeFile(path.join(handlerFolder, 'index.mjs'), warmUpFunction);
|
|
206
194
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
195
|
+
if (tracing) {
|
|
196
|
+
await execAsync('npm init -y', { cwd: handlerFolder });
|
|
197
|
+
await execAsync('npm install --save aws-xray-sdk-core', { cwd: handlerFolder });
|
|
198
|
+
}
|
|
211
199
|
}
|
|
212
200
|
|
|
213
201
|
/**
|
|
214
202
|
* @description Add warmer function to service
|
|
215
203
|
* */
|
|
216
204
|
function addWarmUpFunctionToService(service, warmerName, warmerConfig) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
205
|
+
// eslint-disable-next-line no-param-reassign
|
|
206
|
+
service.functions[`warmUpPlugin${capitalize(warmerName)}`] = {
|
|
207
|
+
description: `Serverless WarmUp Plugin (warmer "${warmerName}")`,
|
|
208
|
+
events: warmerConfig.events,
|
|
209
|
+
handler: warmerConfig.pathHandler.split(path.sep).join(path.posix.sep),
|
|
210
|
+
memorySize: warmerConfig.memorySize,
|
|
211
|
+
name: warmerConfig.name,
|
|
212
|
+
...(warmerConfig.architecture ? { architecture: warmerConfig.architecture } : {}),
|
|
213
|
+
runtime: 'nodejs24.x',
|
|
214
|
+
package: warmerConfig.package,
|
|
215
|
+
timeout: warmerConfig.timeout,
|
|
216
|
+
...(Object.keys(warmerConfig.environment).length
|
|
217
|
+
? { environment: warmerConfig.environment }
|
|
218
|
+
: {}),
|
|
219
|
+
...(warmerConfig.tracing !== undefined ? { tracing: warmerConfig.tracing } : {}),
|
|
220
|
+
...(warmerConfig.logRetentionInDays !== undefined
|
|
221
|
+
? { logRetentionInDays: warmerConfig.logRetentionInDays }
|
|
222
|
+
: {}),
|
|
223
|
+
...(warmerConfig.roleName ? { roleName: warmerConfig.roleName } : {}),
|
|
224
|
+
...(warmerConfig.role ? { role: warmerConfig.role } : {}),
|
|
225
|
+
...(warmerConfig.tags ? { tags: warmerConfig.tags } : {}),
|
|
226
|
+
...(warmerConfig.vpc ? { vpc: warmerConfig.vpc } : {}),
|
|
227
|
+
layers: [],
|
|
228
|
+
};
|
|
241
229
|
}
|
|
242
230
|
|
|
243
231
|
module.exports = {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
232
|
+
addWarmUpFunctionRoleToResources,
|
|
233
|
+
createWarmUpFunctionArtifact,
|
|
234
|
+
addWarmUpFunctionToService,
|
|
247
235
|
};
|
package/.eslintignore
DELETED