aws-lambda-devkit 0.1.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.
Files changed (183) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/LICENSE +21 -0
  3. package/README.md +214 -0
  4. package/dist/aws/batch-response.d.ts +8 -0
  5. package/dist/aws/batch-response.d.ts.map +1 -0
  6. package/dist/aws/batch-response.js +12 -0
  7. package/dist/aws/batch-response.js.map +1 -0
  8. package/dist/aws/clients.d.ts +6 -0
  9. package/dist/aws/clients.d.ts.map +1 -0
  10. package/dist/aws/clients.js +30 -0
  11. package/dist/aws/clients.js.map +1 -0
  12. package/dist/aws/sns-publish.d.ts +10 -0
  13. package/dist/aws/sns-publish.d.ts.map +1 -0
  14. package/dist/aws/sns-publish.js +17 -0
  15. package/dist/aws/sns-publish.js.map +1 -0
  16. package/dist/aws/sqs-listen.d.ts +17 -0
  17. package/dist/aws/sqs-listen.d.ts.map +1 -0
  18. package/dist/aws/sqs-listen.js +113 -0
  19. package/dist/aws/sqs-listen.js.map +1 -0
  20. package/dist/aws/sqs-process.d.ts +39 -0
  21. package/dist/aws/sqs-process.d.ts.map +1 -0
  22. package/dist/aws/sqs-process.js +95 -0
  23. package/dist/aws/sqs-process.js.map +1 -0
  24. package/dist/aws/sqs-send.d.ts +15 -0
  25. package/dist/aws/sqs-send.d.ts.map +1 -0
  26. package/dist/aws/sqs-send.js +27 -0
  27. package/dist/aws/sqs-send.js.map +1 -0
  28. package/dist/aws/sqs-visibility.d.ts +10 -0
  29. package/dist/aws/sqs-visibility.d.ts.map +1 -0
  30. package/dist/aws/sqs-visibility.js +29 -0
  31. package/dist/aws/sqs-visibility.js.map +1 -0
  32. package/dist/cli.d.ts +3 -0
  33. package/dist/cli.d.ts.map +1 -0
  34. package/dist/cli.js +187 -0
  35. package/dist/cli.js.map +1 -0
  36. package/dist/commands/config-cmd.d.ts +5 -0
  37. package/dist/commands/config-cmd.d.ts.map +1 -0
  38. package/dist/commands/config-cmd.js +8 -0
  39. package/dist/commands/config-cmd.js.map +1 -0
  40. package/dist/commands/config.d.ts +2 -0
  41. package/dist/commands/config.d.ts.map +1 -0
  42. package/dist/commands/config.js +24 -0
  43. package/dist/commands/config.js.map +1 -0
  44. package/dist/commands/init.d.ts +7 -0
  45. package/dist/commands/init.d.ts.map +1 -0
  46. package/dist/commands/init.js +59 -0
  47. package/dist/commands/init.js.map +1 -0
  48. package/dist/commands/list.d.ts +4 -0
  49. package/dist/commands/list.d.ts.map +1 -0
  50. package/dist/commands/list.js +23 -0
  51. package/dist/commands/list.js.map +1 -0
  52. package/dist/commands/listen.d.ts +20 -0
  53. package/dist/commands/listen.d.ts.map +1 -0
  54. package/dist/commands/listen.js +36 -0
  55. package/dist/commands/listen.js.map +1 -0
  56. package/dist/commands/send.d.ts +17 -0
  57. package/dist/commands/send.d.ts.map +1 -0
  58. package/dist/commands/send.js +51 -0
  59. package/dist/commands/send.js.map +1 -0
  60. package/dist/commands/test.d.ts +23 -0
  61. package/dist/commands/test.d.ts.map +1 -0
  62. package/dist/commands/test.js +123 -0
  63. package/dist/commands/test.js.map +1 -0
  64. package/dist/config/env.d.ts +8 -0
  65. package/dist/config/env.d.ts.map +1 -0
  66. package/dist/config/env.js +16 -0
  67. package/dist/config/env.js.map +1 -0
  68. package/dist/config/load.d.ts +9 -0
  69. package/dist/config/load.d.ts.map +1 -0
  70. package/dist/config/load.js +72 -0
  71. package/dist/config/load.js.map +1 -0
  72. package/dist/config/merge.d.ts +36 -0
  73. package/dist/config/merge.d.ts.map +1 -0
  74. package/dist/config/merge.js +89 -0
  75. package/dist/config/merge.js.map +1 -0
  76. package/dist/config/project-env.d.ts +34 -0
  77. package/dist/config/project-env.d.ts.map +1 -0
  78. package/dist/config/project-env.js +90 -0
  79. package/dist/config/project-env.js.map +1 -0
  80. package/dist/config/schema.d.ts +27 -0
  81. package/dist/config/schema.d.ts.map +1 -0
  82. package/dist/config/schema.js +123 -0
  83. package/dist/config/schema.js.map +1 -0
  84. package/dist/config/types.d.ts +167 -0
  85. package/dist/config/types.d.ts.map +1 -0
  86. package/dist/config/types.js +2 -0
  87. package/dist/config/types.js.map +1 -0
  88. package/dist/events/apigw.d.ts +41 -0
  89. package/dist/events/apigw.d.ts.map +1 -0
  90. package/dist/events/apigw.js +43 -0
  91. package/dist/events/apigw.js.map +1 -0
  92. package/dist/events/eventbridge.d.ts +16 -0
  93. package/dist/events/eventbridge.d.ts.map +1 -0
  94. package/dist/events/eventbridge.js +19 -0
  95. package/dist/events/eventbridge.js.map +1 -0
  96. package/dist/events/index.d.ts +17 -0
  97. package/dist/events/index.d.ts.map +1 -0
  98. package/dist/events/index.js +50 -0
  99. package/dist/events/index.js.map +1 -0
  100. package/dist/events/s3.d.ts +45 -0
  101. package/dist/events/s3.d.ts.map +1 -0
  102. package/dist/events/s3.js +44 -0
  103. package/dist/events/s3.js.map +1 -0
  104. package/dist/events/schedule.d.ts +12 -0
  105. package/dist/events/schedule.d.ts.map +1 -0
  106. package/dist/events/schedule.js +15 -0
  107. package/dist/events/schedule.js.map +1 -0
  108. package/dist/events/sns.d.ts +24 -0
  109. package/dist/events/sns.d.ts.map +1 -0
  110. package/dist/events/sns.js +31 -0
  111. package/dist/events/sns.js.map +1 -0
  112. package/dist/events/sqs-record.d.ts +44 -0
  113. package/dist/events/sqs-record.d.ts.map +1 -0
  114. package/dist/events/sqs-record.js +75 -0
  115. package/dist/events/sqs-record.js.map +1 -0
  116. package/dist/events/sqs.d.ts +21 -0
  117. package/dist/events/sqs.d.ts.map +1 -0
  118. package/dist/events/sqs.js +28 -0
  119. package/dist/events/sqs.js.map +1 -0
  120. package/dist/events/util.d.ts +2 -0
  121. package/dist/events/util.d.ts.map +1 -0
  122. package/dist/events/util.js +7 -0
  123. package/dist/events/util.js.map +1 -0
  124. package/dist/index.d.ts +15 -0
  125. package/dist/index.d.ts.map +1 -0
  126. package/dist/index.js +14 -0
  127. package/dist/index.js.map +1 -0
  128. package/dist/peer-resolve.d.ts +5 -0
  129. package/dist/peer-resolve.d.ts.map +1 -0
  130. package/dist/peer-resolve.js +44 -0
  131. package/dist/peer-resolve.js.map +1 -0
  132. package/dist/runtime/asset-links.d.ts +15 -0
  133. package/dist/runtime/asset-links.d.ts.map +1 -0
  134. package/dist/runtime/asset-links.js +42 -0
  135. package/dist/runtime/asset-links.js.map +1 -0
  136. package/dist/runtime/clear-caches.d.ts +5 -0
  137. package/dist/runtime/clear-caches.d.ts.map +1 -0
  138. package/dist/runtime/clear-caches.js +8 -0
  139. package/dist/runtime/clear-caches.js.map +1 -0
  140. package/dist/runtime/context.d.ts +10 -0
  141. package/dist/runtime/context.d.ts.map +1 -0
  142. package/dist/runtime/context.js +42 -0
  143. package/dist/runtime/context.js.map +1 -0
  144. package/dist/runtime/handler-cache.d.ts +6 -0
  145. package/dist/runtime/handler-cache.d.ts.map +1 -0
  146. package/dist/runtime/handler-cache.js +14 -0
  147. package/dist/runtime/handler-cache.js.map +1 -0
  148. package/dist/runtime/invoke.d.ts +32 -0
  149. package/dist/runtime/invoke.d.ts.map +1 -0
  150. package/dist/runtime/invoke.js +111 -0
  151. package/dist/runtime/invoke.js.map +1 -0
  152. package/dist/runtime/loader.d.ts +17 -0
  153. package/dist/runtime/loader.d.ts.map +1 -0
  154. package/dist/runtime/loader.js +76 -0
  155. package/dist/runtime/loader.js.map +1 -0
  156. package/dist/runtime/logs.d.ts +19 -0
  157. package/dist/runtime/logs.d.ts.map +1 -0
  158. package/dist/runtime/logs.js +125 -0
  159. package/dist/runtime/logs.js.map +1 -0
  160. package/dist/util/payload.d.ts +13 -0
  161. package/dist/util/payload.d.ts.map +1 -0
  162. package/dist/util/payload.js +40 -0
  163. package/dist/util/payload.js.map +1 -0
  164. package/dist/util/tsx-register.d.ts +4 -0
  165. package/dist/util/tsx-register.d.ts.map +1 -0
  166. package/dist/util/tsx-register.js +27 -0
  167. package/dist/util/tsx-register.js.map +1 -0
  168. package/dist/version.d.ts +2 -0
  169. package/dist/version.d.ts.map +1 -0
  170. package/dist/version.js +2 -0
  171. package/dist/version.js.map +1 -0
  172. package/docs/README.md +23 -0
  173. package/docs/commands.md +294 -0
  174. package/docs/configuration.md +652 -0
  175. package/docs/getting-started.md +400 -0
  176. package/docs/recipes.md +743 -0
  177. package/docs/troubleshooting.md +393 -0
  178. package/package.json +76 -0
  179. package/templates/.env.example +5 -0
  180. package/templates/.vscode/launch.json +14 -0
  181. package/templates/events/sample.json +4 -0
  182. package/templates/lamkit.config.js +38 -0
  183. package/templates/lamkit.config.ts +27 -0
@@ -0,0 +1,400 @@
1
+ # Getting started
2
+
3
+ This guide walks you from zero to a working local Lambda invoke. You only need basic Node.js knowledge.
4
+
5
+ **Time:** about 15 minutes
6
+ **Goal:** run `lamkit test` and see CloudWatch-style logs on your machine
7
+
8
+ | | |
9
+ |---|---|
10
+ | Install | `npm install -D aws-lambda-devkit` |
11
+ | Run CLI | `npx lamkit test` |
12
+ | Import in config | `import { defineConfig } from 'aws-lambda-devkit'` |
13
+
14
+ ---
15
+
16
+ ## What problem does this solve?
17
+
18
+ In production, AWS Lambda runs your `handler` when an event arrives (SQS message, HTTP request, etc.). To test changes locally you could:
19
+
20
+ - Write huge JSON event files by hand
21
+ - Deploy to dev for every small change
22
+ - Run a heavy emulator stack
23
+
24
+ Lambda DevKit gives you a lighter path:
25
+
26
+ 1. You keep **one** `handler` export — the same code you deploy
27
+ 2. You add a small **`lamkit.config.js`**
28
+ 3. You run **`lamkit test --data '{"id":"1"}'`** and lamkit builds a realistic event for you
29
+
30
+ No changes inside your handler. No deploy required for the basic loop.
31
+
32
+ ---
33
+
34
+ ## What Lambda DevKit does and does not do
35
+
36
+ | Does | Does not |
37
+ |------|----------|
38
+ | Invoke `handler` locally | Deploy Lambdas |
39
+ | Build SQS / HTTP / SNS shaped events | Create SQS queues or SNS topics |
40
+ | Print START / END / REPORT logs | Replace SAM or CDK |
41
+ | Optionally send/listen on **existing** dev queues | Modify your production handler code |
42
+
43
+ ---
44
+
45
+ ## Prerequisites
46
+
47
+ | Requirement | Details |
48
+ |-------------|---------|
49
+ | Node.js | Version 20 or newer (`node -v`) |
50
+ | npm | Comes with Node |
51
+ | A handler | Or you will create one in Step 3 |
52
+
53
+ **Optional packages** (install only when needed):
54
+
55
+ ```bash
56
+ npm install -D tsx # TypeScript handler or lamkit.config.ts
57
+ npm install -D @aws-sdk/client-sqs # lamkit send sqs / lamkit listen
58
+ npm install -D @aws-sdk/client-sns # lamkit send sns
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Step 1 — Create a project folder
64
+
65
+ You can use an existing Lambda repo or a new folder:
66
+
67
+ ```bash
68
+ mkdir my-lambda-worker
69
+ cd my-lambda-worker
70
+ npm init -y
71
+ ```
72
+
73
+ Your folder will grow to look like this:
74
+
75
+ ```
76
+ my-lambda-worker/
77
+ ├── package.json
78
+ ├── lamkit.config.js ← created in Step 2
79
+ ├── .env ← copy from .env.example
80
+ ├── .env.example
81
+ ├── events/
82
+ │ └── sample.json
83
+ └── src/
84
+ └── lambda/
85
+ └── handler.js ← created in Step 3
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Step 2 — Install the npm package
91
+
92
+ Package name on npm is **`aws-lambda-devkit`** (CLI command is still **`lamkit`**).
93
+
94
+ ```bash
95
+ npm install -D aws-lambda-devkit
96
+ ```
97
+
98
+ Verify the CLI is available:
99
+
100
+ ```bash
101
+ npx lamkit --help
102
+ ```
103
+
104
+ ### Add npm scripts (recommended)
105
+
106
+ Edit `package.json`:
107
+
108
+ ```json
109
+ {
110
+ "name": "my-lambda-worker",
111
+ "type": "module",
112
+ "scripts": {
113
+ "test:lambda": "lamkit test",
114
+ "build": "tsc"
115
+ },
116
+ "devDependencies": {
117
+ "aws-lambda-devkit": "^0.1.0"
118
+ }
119
+ }
120
+ ```
121
+
122
+ Or scaffold everything with:
123
+
124
+ ```bash
125
+ npx lamkit init --yes
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Step 3 — Scaffold config and env files
131
+
132
+ ```bash
133
+ npx lamkit init
134
+ cp .env.example .env
135
+ ```
136
+
137
+ **`lamkit.config.js`** (created for you):
138
+
139
+ ```js
140
+ export default {
141
+ functions: [
142
+ {
143
+ name: 'worker',
144
+ entry: './src/lambda/handler.js',
145
+ trigger: 'sqs',
146
+ },
147
+ ],
148
+ };
149
+ ```
150
+
151
+ **`.env.example`** (minimal):
152
+
153
+ ```env
154
+ AWS_REGION=us-east-1
155
+
156
+ # Only needed for lamkit send / lamkit listen
157
+ # AWS_ACCESS_KEY_ID=
158
+ # AWS_SECRET_ACCESS_KEY=
159
+ ```
160
+
161
+ For `lamkit test` alone, `.env` can stay almost empty. Lamkit loads it automatically if present.
162
+
163
+ ---
164
+
165
+ ## Step 4 — Write your handler
166
+
167
+ Create **`src/lambda/handler.js`**:
168
+
169
+ ```js
170
+ /**
171
+ * Production handler — deploy this same file (or its compiled output).
172
+ * Do NOT import aws-lambda-devkit here.
173
+ */
174
+ export const handler = async (event, context) => {
175
+ console.log('RequestId:', context.awsRequestId);
176
+ console.log('Record count:', event.Records?.length ?? 0);
177
+
178
+ for (const record of event.Records ?? []) {
179
+ const body = JSON.parse(record.body);
180
+ console.log('Processing message:', body);
181
+ // your business logic here
182
+ }
183
+
184
+ // SQS handlers often return nothing or partial batch failures:
185
+ // return { batchItemFailures: [{ itemIdentifier: 'message-id' }] };
186
+ };
187
+ ```
188
+
189
+ **Important rules:**
190
+
191
+ | Rule | Why |
192
+ |------|-----|
193
+ | Export must be named `handler` (or default export) | Lamkit looks for this symbol |
194
+ | Same file you deploy | Avoids "works locally, different in AWS" |
195
+ | No `aws-lambda-devkit` import in handler | Handler stays production-pure |
196
+
197
+ ---
198
+
199
+ ## Step 5 — Run your first test
200
+
201
+ ```bash
202
+ npx lamkit test --data '{"orderId":"ord_123","amount":42}'
203
+ ```
204
+
205
+ Because you have only one function, the name `worker` is optional.
206
+
207
+ ### What you should see
208
+
209
+ ```
210
+ ✓ worker (sqs) — 12ms
211
+
212
+ Logs:
213
+ START RequestId: f47ac10b-58cc-4372-a567-0e02b2c3d479 Version: $LATEST
214
+ RequestId: f47ac10b-58cc-4372-a567-0e02b2c3d479
215
+ Record count: 1
216
+ Processing message: { orderId: 'ord_123', amount: 42 }
217
+ END RequestId: f47ac10b-58cc-4372-a567-0e02b2c3d479
218
+ REPORT RequestId: f47ac10b-58cc-4372-a567-0e02b2c3d479 Duration: 12.00 ms ...
219
+ ```
220
+
221
+ The green `✓` line means lamkit loaded your handler and the invoke finished without an uncaught error.
222
+
223
+ ### What lamkit built for you
224
+
225
+ With `trigger: 'sqs'`, your `--data` JSON becomes the **body** of an SQS record inside a full `SQSEvent`:
226
+
227
+ ```json
228
+ {
229
+ "Records": [
230
+ {
231
+ "messageId": "...",
232
+ "body": "{\"orderId\":\"ord_123\",\"amount\":42}",
233
+ "eventSource": "aws:sqs",
234
+ "awsRegion": "us-east-1"
235
+ }
236
+ ]
237
+ }
238
+ ```
239
+
240
+ Preview without invoking:
241
+
242
+ ```bash
243
+ npx lamkit test --dry-run --data '{"orderId":"ord_123"}'
244
+ ```
245
+
246
+ ---
247
+
248
+ ## Step 6 — Use a payload file
249
+
250
+ Create **`events/order-created.json`**:
251
+
252
+ ```json
253
+ {
254
+ "orderId": "ord_456",
255
+ "customerId": "cust_789",
256
+ "lines": [{ "sku": "ITEM-1", "qty": 2 }]
257
+ }
258
+ ```
259
+
260
+ Run:
261
+
262
+ ```bash
263
+ npx lamkit test --data-file events/order-created.json
264
+ # equivalent:
265
+ npx lamkit test --data @events/order-created.json
266
+ ```
267
+
268
+ ---
269
+
270
+ ## Step 7 — Inspect configuration
271
+
272
+ ```bash
273
+ npx lamkit list
274
+ npx lamkit config worker
275
+ ```
276
+
277
+ Use this when env vars or queue URLs do not resolve the way you expect.
278
+
279
+ ---
280
+
281
+ ## Step 8 — Debug with breakpoints (optional)
282
+
283
+ ### VS Code
284
+
285
+ `lamkit init` creates **`.vscode/launch.json`**. Open the Run and Debug panel and start **"lamkit test (inspect)"**.
286
+
287
+ ### Terminal
288
+
289
+ ```bash
290
+ npx lamkit test --inspect-brk --data '{"orderId":"1"}'
291
+ ```
292
+
293
+ Attach your debugger to the Node process (or use Chrome at `chrome://inspect`).
294
+
295
+ Set a breakpoint inside `handler` and step through your code.
296
+
297
+ ---
298
+
299
+ ## How the pieces fit together
300
+
301
+ ```
302
+ ┌─────────────────┐
303
+ │ lamkit.config.js │ names, entry path, trigger, queue URLs
304
+ └────────┬────────┘
305
+
306
+ ┌────────▼────────┐
307
+ │ .env (optional) │ AWS_REGION, secrets, queue URLs
308
+ └────────┬────────┘
309
+
310
+ ┌────────▼────────┐
311
+ │ lamkit test │ builds event from --data / --event / config
312
+ └────────┬────────┘
313
+
314
+ ┌────────▼────────┐
315
+ │ your handler │ export const handler = async (event) => ...
316
+ └────────┬────────┘
317
+
318
+ ┌────────▼────────┐
319
+ │ console output │ START, your logs, END, REPORT
320
+ └─────────────────┘
321
+ ```
322
+
323
+ **Offline path (`lamkit test`):** no AWS network calls from lamkit itself.
324
+ **Online path (`send` / `listen`):** optional; see [Recipes — Real SQS](recipes.md#recipe-12--real-sqs-send-then-listen-locally).
325
+
326
+ ---
327
+
328
+ ## When you already have a compiled `dist/` folder
329
+
330
+ Many teams deploy `./dist/handler.js` after TypeScript compile. Point `entry` at dist:
331
+
332
+ ```js
333
+ export default {
334
+ functions: [
335
+ {
336
+ name: 'worker',
337
+ entry: './dist/handler.js',
338
+ trigger: 'sqs',
339
+ },
340
+ ],
341
+ };
342
+ ```
343
+
344
+ Workflow:
345
+
346
+ ```bash
347
+ npm run build
348
+ npx lamkit test --data '{"id":"1"}'
349
+ ```
350
+
351
+ ---
352
+
353
+ ## Default payload in config
354
+
355
+ Avoid typing `--data` every time:
356
+
357
+ ```js
358
+ export default {
359
+ functions: [
360
+ {
361
+ name: 'worker',
362
+ entry: './src/lambda/handler.js',
363
+ trigger: 'sqs',
364
+ test: {
365
+ data: { type: 'PING', source: 'local' },
366
+ },
367
+ },
368
+ ],
369
+ };
370
+ ```
371
+
372
+ ```bash
373
+ npx lamkit test
374
+ ```
375
+
376
+ ---
377
+
378
+ ## Common first-day mistakes
379
+
380
+ | Mistake | Fix |
381
+ |---------|-----|
382
+ | `Handler entry not found` | Run `npm run build` or fix `entry` path |
383
+ | `must export a named "handler"` | Add `export const handler = ...` |
384
+ | Running from wrong directory | `cd` to folder with `lamkit.config.js` or use `--cwd` |
385
+ | Empty `event.Records` | Set `trigger: 'sqs'` (default) for queue handlers |
386
+ | Expecting lamkit to create queues | You supply existing `queueUrl` for send/listen |
387
+ | Handler works in AWS but not locally | Missing `.env` vars or wrong `entry` (src vs dist) |
388
+
389
+ More fixes: [Troubleshooting](troubleshooting.md)
390
+
391
+ ---
392
+
393
+ ## Where to go next
394
+
395
+ | I want to… | Read |
396
+ |------------|------|
397
+ | Every CLI flag with examples | [Commands reference](commands.md) |
398
+ | All config fields explained | [Configuration reference](configuration.md) |
399
+ | Monorepo, TypeScript, real SQS, HTTP, CI | [Recipes](recipes.md) |
400
+ | Fix an error | [Troubleshooting](troubleshooting.md) |