@nikovirtala/projen-lambda-function-construct-generator 0.0.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/.jsii +4490 -0
- package/API.md +404 -0
- package/LICENSE +19 -0
- package/README.md +260 -0
- package/lib/index.d.ts +99 -0
- package/lib/index.js +245 -0
- package/package.json +99 -0
package/API.md
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
# API Reference <a name="API Reference" id="api-reference"></a>
|
|
2
|
+
|
|
3
|
+
## Constructs <a name="Constructs" id="Constructs"></a>
|
|
4
|
+
|
|
5
|
+
### LambdaFunctionConstructGenerator <a name="LambdaFunctionConstructGenerator" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator"></a>
|
|
6
|
+
|
|
7
|
+
A projen component that generates AWS CDK Lambda Function constructs and bundles their code assets using esbuild.
|
|
8
|
+
|
|
9
|
+
The bundling happens during projen execution, not during CDK synth, enabling a "build once, deploy many" pattern.
|
|
10
|
+
|
|
11
|
+
#### Initializers <a name="Initializers" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.Initializer"></a>
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { LambdaFunctionConstructGenerator } from '@nikovirtala/projen-lambda-function-construct-generator'
|
|
15
|
+
|
|
16
|
+
new LambdaFunctionConstructGenerator(project: NodeProject, options?: LambdaFunctionConstructGeneratorOptions)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
| **Name** | **Type** | **Description** |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.Initializer.parameter.project">project</a></code> | <code>projen.javascript.NodeProject</code> | *No description.* |
|
|
22
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.Initializer.parameter.options">options</a></code> | <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions">LambdaFunctionConstructGeneratorOptions</a></code> | *No description.* |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
##### `project`<sup>Required</sup> <a name="project" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.Initializer.parameter.project"></a>
|
|
27
|
+
|
|
28
|
+
- *Type:* projen.javascript.NodeProject
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
##### `options`<sup>Optional</sup> <a name="options" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.Initializer.parameter.options"></a>
|
|
33
|
+
|
|
34
|
+
- *Type:* <a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions">LambdaFunctionConstructGeneratorOptions</a>
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
#### Methods <a name="Methods" id="Methods"></a>
|
|
39
|
+
|
|
40
|
+
| **Name** | **Description** |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.toString">toString</a></code> | Returns a string representation of this construct. |
|
|
43
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.postSynthesize">postSynthesize</a></code> | Called after synthesis. |
|
|
44
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.preSynthesize">preSynthesize</a></code> | Called before synthesis. |
|
|
45
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.synthesize">synthesize</a></code> | Synthesizes files to the project output directory. |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
##### `toString` <a name="toString" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.toString"></a>
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
public toString(): string
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Returns a string representation of this construct.
|
|
56
|
+
|
|
57
|
+
##### `postSynthesize` <a name="postSynthesize" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.postSynthesize"></a>
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
public postSynthesize(): void
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Called after synthesis.
|
|
64
|
+
|
|
65
|
+
Order is *not* guaranteed.
|
|
66
|
+
|
|
67
|
+
##### `preSynthesize` <a name="preSynthesize" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.preSynthesize"></a>
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
public preSynthesize(): void
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Called before synthesis.
|
|
74
|
+
|
|
75
|
+
##### `synthesize` <a name="synthesize" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.synthesize"></a>
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
public synthesize(): void
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Synthesizes files to the project output directory.
|
|
82
|
+
|
|
83
|
+
#### Static Functions <a name="Static Functions" id="Static Functions"></a>
|
|
84
|
+
|
|
85
|
+
| **Name** | **Description** |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.isConstruct">isConstruct</a></code> | Checks if `x` is a construct. |
|
|
88
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.isComponent">isComponent</a></code> | Test whether the given construct is a component. |
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
##### `isConstruct` <a name="isConstruct" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.isConstruct"></a>
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { LambdaFunctionConstructGenerator } from '@nikovirtala/projen-lambda-function-construct-generator'
|
|
96
|
+
|
|
97
|
+
LambdaFunctionConstructGenerator.isConstruct(x: any)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Checks if `x` is a construct.
|
|
101
|
+
|
|
102
|
+
Use this method instead of `instanceof` to properly detect `Construct`
|
|
103
|
+
instances, even when the construct library is symlinked.
|
|
104
|
+
|
|
105
|
+
Explanation: in JavaScript, multiple copies of the `constructs` library on
|
|
106
|
+
disk are seen as independent, completely different libraries. As a
|
|
107
|
+
consequence, the class `Construct` in each copy of the `constructs` library
|
|
108
|
+
is seen as a different class, and an instance of one class will not test as
|
|
109
|
+
`instanceof` the other class. `npm install` will not create installations
|
|
110
|
+
like this, but users may manually symlink construct libraries together or
|
|
111
|
+
use a monorepo tool: in those cases, multiple copies of the `constructs`
|
|
112
|
+
library can be accidentally installed, and `instanceof` will behave
|
|
113
|
+
unpredictably. It is safest to avoid using `instanceof`, and using
|
|
114
|
+
this type-testing method instead.
|
|
115
|
+
|
|
116
|
+
###### `x`<sup>Required</sup> <a name="x" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.isConstruct.parameter.x"></a>
|
|
117
|
+
|
|
118
|
+
- *Type:* any
|
|
119
|
+
|
|
120
|
+
Any object.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
##### `isComponent` <a name="isComponent" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.isComponent"></a>
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { LambdaFunctionConstructGenerator } from '@nikovirtala/projen-lambda-function-construct-generator'
|
|
128
|
+
|
|
129
|
+
LambdaFunctionConstructGenerator.isComponent(x: any)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Test whether the given construct is a component.
|
|
133
|
+
|
|
134
|
+
###### `x`<sup>Required</sup> <a name="x" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.isComponent.parameter.x"></a>
|
|
135
|
+
|
|
136
|
+
- *Type:* any
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
141
|
+
|
|
142
|
+
| **Name** | **Type** | **Description** |
|
|
143
|
+
| --- | --- | --- |
|
|
144
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
|
|
145
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.project">project</a></code> | <code>projen.Project</code> | *No description.* |
|
|
146
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.esbuildOptions">esbuildOptions</a></code> | <code>@mrgrain/cdk-esbuild.BuildOptions</code> | *No description.* |
|
|
147
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.filePattern">filePattern</a></code> | <code>string</code> | *No description.* |
|
|
148
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.outputDir">outputDir</a></code> | <code>string</code> | *No description.* |
|
|
149
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.sourceDir">sourceDir</a></code> | <code>string</code> | *No description.* |
|
|
150
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.baseConstructClass">baseConstructClass</a></code> | <code>string</code> | *No description.* |
|
|
151
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.baseConstructImport">baseConstructImport</a></code> | <code>string</code> | *No description.* |
|
|
152
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.baseConstructPackage">baseConstructPackage</a></code> | <code>string</code> | *No description.* |
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
##### `node`<sup>Required</sup> <a name="node" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.node"></a>
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
public readonly node: Node;
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
- *Type:* constructs.Node
|
|
163
|
+
|
|
164
|
+
The tree node.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
##### `project`<sup>Required</sup> <a name="project" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.project"></a>
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
public readonly project: Project;
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
- *Type:* projen.Project
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
##### `esbuildOptions`<sup>Required</sup> <a name="esbuildOptions" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.esbuildOptions"></a>
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
public readonly esbuildOptions: BuildOptions;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
- *Type:* @mrgrain/cdk-esbuild.BuildOptions
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
##### `filePattern`<sup>Required</sup> <a name="filePattern" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.filePattern"></a>
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
public readonly filePattern: string;
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
- *Type:* string
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
##### `outputDir`<sup>Required</sup> <a name="outputDir" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.outputDir"></a>
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
public readonly outputDir: string;
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
- *Type:* string
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
##### `sourceDir`<sup>Required</sup> <a name="sourceDir" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.sourceDir"></a>
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
public readonly sourceDir: string;
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
- *Type:* string
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
##### `baseConstructClass`<sup>Optional</sup> <a name="baseConstructClass" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.baseConstructClass"></a>
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
public readonly baseConstructClass: string;
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
- *Type:* string
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
##### `baseConstructImport`<sup>Optional</sup> <a name="baseConstructImport" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.baseConstructImport"></a>
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
public readonly baseConstructImport: string;
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
- *Type:* string
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
##### `baseConstructPackage`<sup>Optional</sup> <a name="baseConstructPackage" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGenerator.property.baseConstructPackage"></a>
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
public readonly baseConstructPackage: string;
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
- *Type:* string
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
## Structs <a name="Structs" id="Structs"></a>
|
|
250
|
+
|
|
251
|
+
### LambdaFunctionConstructGeneratorOptions <a name="LambdaFunctionConstructGeneratorOptions" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions"></a>
|
|
252
|
+
|
|
253
|
+
Options for the LambdaFunctionConstructGenerator.
|
|
254
|
+
|
|
255
|
+
#### Initializer <a name="Initializer" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.Initializer"></a>
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
import { LambdaFunctionConstructGeneratorOptions } from '@nikovirtala/projen-lambda-function-construct-generator'
|
|
259
|
+
|
|
260
|
+
const lambdaFunctionConstructGeneratorOptions: LambdaFunctionConstructGeneratorOptions = { ... }
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
264
|
+
|
|
265
|
+
| **Name** | **Type** | **Description** |
|
|
266
|
+
| --- | --- | --- |
|
|
267
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.addDependencies">addDependencies</a></code> | <code>boolean</code> | Whether to automatically add the required dependencies. |
|
|
268
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.baseConstructClass">baseConstructClass</a></code> | <code>string</code> | Name of the construct class to extend. |
|
|
269
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.baseConstructImport">baseConstructImport</a></code> | <code>string</code> | Import statement for the base construct. |
|
|
270
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.baseConstructPackage">baseConstructPackage</a></code> | <code>string</code> | Package name to add as dependency for the base construct. |
|
|
271
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.esbuildOptions">esbuildOptions</a></code> | <code>@mrgrain/cdk-esbuild.BuildOptions</code> | esbuild options to customize the bundling process. |
|
|
272
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.filePattern">filePattern</a></code> | <code>string</code> | File pattern to identify Lambda Function handlers. |
|
|
273
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.outputDir">outputDir</a></code> | <code>string</code> | Output directory where Lambda Function constructs will be generated. |
|
|
274
|
+
| <code><a href="#@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.sourceDir">sourceDir</a></code> | <code>string</code> | Source directory where Lambda Function handlers are located. |
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
##### `addDependencies`<sup>Optional</sup> <a name="addDependencies" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.addDependencies"></a>
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
public readonly addDependencies: boolean;
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
- *Type:* boolean
|
|
285
|
+
- *Default:* true
|
|
286
|
+
|
|
287
|
+
Whether to automatically add the required dependencies.
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
##### `baseConstructClass`<sup>Optional</sup> <a name="baseConstructClass" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.baseConstructClass"></a>
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
public readonly baseConstructClass: string;
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
- *Type:* string
|
|
298
|
+
- *Default:* "aws_lambda.Function"
|
|
299
|
+
|
|
300
|
+
Name of the construct class to extend.
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
*Example*
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
"NodejsFunction"
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
##### `baseConstructImport`<sup>Optional</sup> <a name="baseConstructImport" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.baseConstructImport"></a>
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
public readonly baseConstructImport: string;
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
- *Type:* string
|
|
318
|
+
- *Default:* "import { aws_lambda } from 'aws-cdk-lib';"
|
|
319
|
+
|
|
320
|
+
Import statement for the base construct.
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
*Example*
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
"import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';"
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
##### `baseConstructPackage`<sup>Optional</sup> <a name="baseConstructPackage" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.baseConstructPackage"></a>
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
public readonly baseConstructPackage: string;
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
- *Type:* string
|
|
338
|
+
- *Default:* "aws-cdk-lib"
|
|
339
|
+
|
|
340
|
+
Package name to add as dependency for the base construct.
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
*Example*
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
"aws-cdk-lib"
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
##### `esbuildOptions`<sup>Optional</sup> <a name="esbuildOptions" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.esbuildOptions"></a>
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
public readonly esbuildOptions: BuildOptions;
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
- *Type:* @mrgrain/cdk-esbuild.BuildOptions
|
|
358
|
+
- *Default:* {}
|
|
359
|
+
|
|
360
|
+
esbuild options to customize the bundling process.
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
##### `filePattern`<sup>Optional</sup> <a name="filePattern" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.filePattern"></a>
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
public readonly filePattern: string;
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
- *Type:* string
|
|
371
|
+
- *Default:* "*.lambda.ts"
|
|
372
|
+
|
|
373
|
+
File pattern to identify Lambda Function handlers.
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
##### `outputDir`<sup>Optional</sup> <a name="outputDir" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.outputDir"></a>
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
public readonly outputDir: string;
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
- *Type:* string
|
|
384
|
+
- *Default:* "src/constructs/lambda"
|
|
385
|
+
|
|
386
|
+
Output directory where Lambda Function constructs will be generated.
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
##### `sourceDir`<sup>Optional</sup> <a name="sourceDir" id="@nikovirtala/projen-lambda-function-construct-generator.LambdaFunctionConstructGeneratorOptions.property.sourceDir"></a>
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
public readonly sourceDir: string;
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
- *Type:* string
|
|
397
|
+
- *Default:* "src/handlers"
|
|
398
|
+
|
|
399
|
+
Source directory where Lambda Function handlers are located.
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2025 Niko Virtala
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# projen-lambda-function-construct-generator
|
|
2
|
+
|
|
3
|
+
A [projen](https://github.com/projen/projen) component to generate AWS CDK Lambda Function constructs and bundle their code assets using [esbuild](https://esbuild.github.io/).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Automatically discovers Lambda Function handlers in a specified directory
|
|
8
|
+
- Generates CDK Construct for each Lambda Function handler
|
|
9
|
+
- Bundles Lambda code assets using esbuild during projen execution (not during CDK synth)
|
|
10
|
+
- Supports customization of esbuild bundling options
|
|
11
|
+
- Enables "build once, deploy many" pattern for Lambda Functions
|
|
12
|
+
- Allows customizing the base construct class for generated Lambda functions
|
|
13
|
+
- Supports multiple generator instances with different configurations
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @nikovirtala/projen-lambda-function-construct-generator
|
|
19
|
+
# or
|
|
20
|
+
yarn add @nikovirtala/projen-lambda-function-construct-generator
|
|
21
|
+
# or
|
|
22
|
+
pnpm add @nikovirtala/projen-lambda-function-construct-generator
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
In your `.projenrc.ts` file:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { awscdk } from "projen";
|
|
31
|
+
import { LambdaFunctionConstructGenerator } from "@nikovirtala/projen-lambda-function-construct-generator";
|
|
32
|
+
|
|
33
|
+
const project = new awscdk.AwsCdkTypeScriptApp({
|
|
34
|
+
// ... your project configuration
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
new LambdaFunctionConstructGenerator(project, {
|
|
38
|
+
// Optional: customize the source directory where Lambda Function handlers are located
|
|
39
|
+
sourceDir: "src/handlers",
|
|
40
|
+
|
|
41
|
+
// Optional: customize the output directory where Lambda Function constructs will be generated
|
|
42
|
+
outputDir: "src/constructs/lambda",
|
|
43
|
+
|
|
44
|
+
// Optional: customize the file pattern to identify Lambda Function handlers
|
|
45
|
+
filePattern: "*.lambda.ts",
|
|
46
|
+
|
|
47
|
+
// Optional: customize the base construct to extend
|
|
48
|
+
baseConstructImport: "import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';",
|
|
49
|
+
baseConstructClass: "NodejsFunction",
|
|
50
|
+
baseConstructPackage: "aws-cdk-lib", // Only needed if it's a separate package
|
|
51
|
+
|
|
52
|
+
// Optional: customize esbuild options
|
|
53
|
+
esbuildOptions: {
|
|
54
|
+
minify: true,
|
|
55
|
+
sourcemap: true,
|
|
56
|
+
// Any other esbuild options
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// You can add multiple generators with different configurations
|
|
61
|
+
new LambdaFunctionConstructGenerator(project, {
|
|
62
|
+
sourceDir: "src/api-handlers",
|
|
63
|
+
outputDir: "src/constructs/api-lambda",
|
|
64
|
+
filePattern: "*.api.ts",
|
|
65
|
+
baseConstructImport: "import { ApiFunction } from '../lib/api-function';",
|
|
66
|
+
baseConstructClass: "ApiFunction",
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
project.synth();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Lambda Handler Examples
|
|
73
|
+
|
|
74
|
+
### Standard Lambda Handler
|
|
75
|
+
|
|
76
|
+
Create a Lambda Function handler file in your source directory (e.g., `src/handlers/hello.lambda.ts`):
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
export async function handler(event: any, context: any) {
|
|
80
|
+
console.log("Event:", JSON.stringify(event, null, 2));
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
statusCode: 200,
|
|
84
|
+
body: JSON.stringify({
|
|
85
|
+
message: "Hello from Lambda!",
|
|
86
|
+
event,
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### API Lambda Handler
|
|
93
|
+
|
|
94
|
+
Create an API Lambda handler file (e.g., `src/api-handlers/user.api.ts`):
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
|
|
98
|
+
|
|
99
|
+
export async function handler(event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> {
|
|
100
|
+
console.log("API Event:", JSON.stringify(event, null, 2));
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
statusCode: 200,
|
|
104
|
+
headers: {
|
|
105
|
+
"Content-Type": "application/json",
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify({
|
|
108
|
+
message: "User API endpoint",
|
|
109
|
+
path: event.path,
|
|
110
|
+
method: event.httpMethod,
|
|
111
|
+
}),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Generated Constructs
|
|
117
|
+
|
|
118
|
+
### Standard Lambda Construct
|
|
119
|
+
|
|
120
|
+
The component will generate a CDK construct for each Lambda Function handler (e.g., `src/constructs/lambda/hello.ts`):
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".
|
|
124
|
+
|
|
125
|
+
import * as path from "path";
|
|
126
|
+
import { fileURLToPath } from "url";
|
|
127
|
+
import { aws_lambda } from "aws-cdk-lib";
|
|
128
|
+
import { Construct } from "constructs";
|
|
129
|
+
|
|
130
|
+
// ES Module compatibility
|
|
131
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
132
|
+
const __dirname = path.dirname(__filename);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Properties for HelloFunction
|
|
136
|
+
*/
|
|
137
|
+
export interface HelloFunctionProps extends Omit<aws_lambda.FunctionProps, "code" | "runtime" | "handler"> {
|
|
138
|
+
/**
|
|
139
|
+
* Override the default runtime
|
|
140
|
+
* @default nodejs22.x
|
|
141
|
+
*/
|
|
142
|
+
readonly runtime?: aws_lambda.Runtime;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* HelloFunction - Lambda Function Construct for hello.lambda.ts
|
|
147
|
+
*/
|
|
148
|
+
export class HelloFunction extends aws_lambda.Function {
|
|
149
|
+
constructor(scope: Construct, id: string, props: HelloFunctionProps = {}) {
|
|
150
|
+
super(scope, id, {
|
|
151
|
+
...props,
|
|
152
|
+
runtime: props.runtime ?? aws_lambda.Runtime.NODEJS_22_X,
|
|
153
|
+
handler: "index.handler",
|
|
154
|
+
code: aws_lambda.Code.fromAsset(path.join(__dirname, "../../../assets/handlers/hello")),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### API Lambda Construct
|
|
161
|
+
|
|
162
|
+
For API handlers, it will generate constructs that extend your custom `ApiFunction` class (e.g., `src/constructs/api-lambda/user.ts`):
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
// ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".
|
|
166
|
+
|
|
167
|
+
import * as path from "path";
|
|
168
|
+
import { fileURLToPath } from "url";
|
|
169
|
+
import { ApiFunction } from "../lib/api-function";
|
|
170
|
+
import { aws_lambda } from "aws-cdk-lib";
|
|
171
|
+
import { Construct } from "constructs";
|
|
172
|
+
|
|
173
|
+
// ES Module compatibility
|
|
174
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
175
|
+
const __dirname = path.dirname(__filename);
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Properties for UserApiFunction
|
|
179
|
+
*/
|
|
180
|
+
export interface UserApiFunctionProps extends Omit<ApiFunctionProps, "code" | "handler"> {
|
|
181
|
+
// No runtime property since ApiFunction handles that
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* UserApiFunction - Lambda Function Construct for user.api.ts
|
|
186
|
+
*/
|
|
187
|
+
export class UserApiFunction extends ApiFunction {
|
|
188
|
+
constructor(scope: Construct, id: string, props: UserApiFunctionProps = {}) {
|
|
189
|
+
super(scope, id, {
|
|
190
|
+
...props,
|
|
191
|
+
handler: "index.handler",
|
|
192
|
+
code: aws_lambda.Code.fromAsset(path.join(__dirname, "../../../assets/handlers/user")),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Using the Generated Constructs
|
|
199
|
+
|
|
200
|
+
### Basic Usage
|
|
201
|
+
|
|
202
|
+
In your CDK stack:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { Stack, StackProps, Duration } from "aws-cdk-lib";
|
|
206
|
+
import { Construct } from "constructs";
|
|
207
|
+
import { HelloFunction } from "../constructs/lambda/hello";
|
|
208
|
+
|
|
209
|
+
export class MyStack extends Stack {
|
|
210
|
+
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
211
|
+
super(scope, id, props);
|
|
212
|
+
|
|
213
|
+
const helloFunction = new HelloFunction(this, "HelloFunction", {
|
|
214
|
+
memorySize: 256,
|
|
215
|
+
timeout: Duration.seconds(30),
|
|
216
|
+
environment: {
|
|
217
|
+
EXAMPLE_VAR: "example-value",
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Using with Custom Base Constructs
|
|
225
|
+
|
|
226
|
+
If you've specified a custom base construct:
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import { Stack, StackProps } from "aws-cdk-lib";
|
|
230
|
+
import { Construct } from "constructs";
|
|
231
|
+
import { HelloFunction } from "../constructs/lambda/hello";
|
|
232
|
+
import { UserApiFunction } from "../constructs/api-lambda/user";
|
|
233
|
+
|
|
234
|
+
export class MyStack extends Stack {
|
|
235
|
+
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
236
|
+
super(scope, id, props);
|
|
237
|
+
|
|
238
|
+
// Using the NodejsFunction-based construct
|
|
239
|
+
const helloFunction = new HelloFunction(this, "HelloFunction", {
|
|
240
|
+
// Properties specific to the NodejsFunction type
|
|
241
|
+
entry: "src/handlers/hello.lambda.ts",
|
|
242
|
+
bundling: {
|
|
243
|
+
minify: true,
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// Using the ApiFunction-based construct
|
|
248
|
+
const userApiFunction = new UserApiFunction(this, "UserApiFunction", {
|
|
249
|
+
// Properties specific to the ApiFunction type
|
|
250
|
+
apiId: "my-api-id",
|
|
251
|
+
routeKey: "GET /users",
|
|
252
|
+
authorizationType: "JWT",
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
MIT
|