@awsless/cli 0.0.1

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 (50) hide show
  1. package/README.MD +487 -0
  2. package/dist/app.json +1 -0
  3. package/dist/app.stage.json +1 -0
  4. package/dist/bin.d.ts +1 -0
  5. package/dist/bin.js +49025 -0
  6. package/dist/build-json-schema.js +1925 -0
  7. package/dist/chunk-2TBBLACH.js +37 -0
  8. package/dist/chunk-3YEPERYO.js +1021 -0
  9. package/dist/chunk-4JFIJMQ6.js +46 -0
  10. package/dist/chunk-5TWBDDXS.js +60 -0
  11. package/dist/chunk-7NRPMOO4.js +876 -0
  12. package/dist/chunk-7XIGSOF4.js +100 -0
  13. package/dist/chunk-DSXFE5X2.js +174 -0
  14. package/dist/chunk-E7FQOYML.js +12 -0
  15. package/dist/chunk-GH475CSF.js +5005 -0
  16. package/dist/chunk-JHYKYQ5P.js +163 -0
  17. package/dist/chunk-LBISIOIM.js +28 -0
  18. package/dist/chunk-RCNT4C4P.js +50 -0
  19. package/dist/chunk-SIAA4J6H.js +21 -0
  20. package/dist/chunk-XNYTWFP6.js +241 -0
  21. package/dist/chunk-Z37AK4IA.js +546 -0
  22. package/dist/chunk-ZKH7AMP3.js +42 -0
  23. package/dist/dist-es-GXHCNXAC.js +489 -0
  24. package/dist/dist-es-J7SL4PXO.js +88 -0
  25. package/dist/dist-es-LL3VAI2X.js +70 -0
  26. package/dist/dist-es-QND3CYLI.js +380 -0
  27. package/dist/dist-es-STVZUSZG.js +21 -0
  28. package/dist/dist-es-TCFHB4OF.js +324 -0
  29. package/dist/dist-es-YFQTZTNE.js +167 -0
  30. package/dist/event-streams-74K5M656.js +244 -0
  31. package/dist/layers/sharp-arm.zip +0 -0
  32. package/dist/loadSso-O7PM54HL.js +592 -0
  33. package/dist/prebuild/icon/HASH +1 -0
  34. package/dist/prebuild/icon/bundle.zip +0 -0
  35. package/dist/prebuild/image/HASH +1 -0
  36. package/dist/prebuild/image/bundle.zip +0 -0
  37. package/dist/prebuild/on-error-log/HASH +1 -0
  38. package/dist/prebuild/on-error-log/bundle.zip +0 -0
  39. package/dist/prebuild/on-failure/HASH +1 -0
  40. package/dist/prebuild/on-failure/bundle.zip +0 -0
  41. package/dist/prebuild/rpc/HASH +1 -0
  42. package/dist/prebuild/rpc/bundle.zip +0 -0
  43. package/dist/prebuild.js +159 -0
  44. package/dist/signin-6SPMGGJN.js +704 -0
  45. package/dist/sso-oidc-5IIWGKXY.js +829 -0
  46. package/dist/stack.json +1 -0
  47. package/dist/stack.stage.json +1 -0
  48. package/dist/sts-6SQWH4BL.js +3788 -0
  49. package/dist/test-global-setup.js +22 -0
  50. package/package.json +120 -0
package/README.MD ADDED
@@ -0,0 +1,487 @@
1
+ <p align="center">Awsless - Infrastructure as a code</p>
2
+
3
+ <div align="center">
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@awsless/awsless.svg?style=flat-square)](https://www.npmjs.org/package/@awsless/awsless)
6
+
7
+ [![npm downloads](https://img.shields.io/npm/dm/@awsless/awsless.svg?style=flat-square)](https://npm-stat.com/charts.html?package=@awsless/awsless)
8
+
9
+ </div>
10
+
11
+ ## Table of Contents
12
+
13
+ - [Table of Contents](#table-of-contents)
14
+ - [Features](#features)
15
+ - [Installing](#installing)
16
+ - [Package manager](#package-manager)
17
+ - [Getting Started](#getting-started)
18
+ - [Base Configuration](#base-configuration)
19
+ - [Modular Stacks](#modular-stacks)
20
+ - [Deploying](#deploying)
21
+ - [Stack Updates](#stack-updates)
22
+ - [Smart Helpers: Call Your Infra Like Functions](#smart-helpers-call-your-infra-like-functions)
23
+ - [Testing Stacks](#testing-stacks)
24
+ - [Core Resources](#core-resources)
25
+ - [Function - AWS Lambda](#function---aws-lambda)
26
+ - [Basic usage](#basic-usage)
27
+ - [Advanced usage](#advanced-usage)
28
+ - [Task](#task)
29
+ - [Basic usage](#basic-usage-1)
30
+ - [Advanced usage](#advanced-usage-1)
31
+ - [Table](#table)
32
+ - [Usage](#usage)
33
+ - [Queue](#queue)
34
+ - [Usage](#usage-1)
35
+ - [Topics](#topics)
36
+ - [Usage](#usage-2)
37
+ - [Crons](#crons)
38
+ - [Usage](#usage-3)
39
+ - [RPC](#rpc)
40
+ - [Smart Functions - Call your infra from code](#smart-functions---call-your-infra-from-code)
41
+ - [Examples](#examples)
42
+ - [Lambda Function](#lambda-function)
43
+ - [Task](#task-1)
44
+ - [Queue](#queue-1)
45
+ - [Topic](#topic)
46
+ - [Config](#config)
47
+
48
+ ## Features
49
+
50
+ ๐Ÿชถ AWS development using JSON config with best practices baked in
51
+
52
+ โšก Deploy APIs, functions, databases, queues, and more โ€” all in one place
53
+
54
+ ๐Ÿ”’ Secure by default with IAM-based permissions and least privilege
55
+
56
+ ๐ŸŒ First-class support for AWS Lambda, DynamoDB, SQS, EventBridge, and more
57
+
58
+ ๐Ÿงช Built-in local development and testing utilities
59
+
60
+ ๐Ÿ”„ Automatic function bundling with support for ES modules and TypeScript
61
+
62
+ ๐Ÿ”„ Types generatation for all resources that can be acessed anywhere in the code
63
+
64
+ ## Installing
65
+
66
+ ### Package manager
67
+
68
+ Using npm:
69
+
70
+ ```bash
71
+ $ npm i @awsless/cli awsless
72
+ ```
73
+
74
+ Using pnpm:
75
+
76
+ ```bash
77
+ $ pnpm i @awsless/cli awsless
78
+ ```
79
+
80
+ ## Getting Started
81
+
82
+ In an Awsless project, your infrastructure is organized into modular stack files, each with its own purpose, and a shared base configuration. Before you begin, make sure you have the AWS CLI installed.
83
+
84
+ ### Base Configuration
85
+
86
+ This is your shared app configuration, which acts as the base stack for the entire project. This should exist in the root of your project.
87
+ `app.json`
88
+
89
+ ```
90
+ {
91
+ "name": "hello-world",
92
+ "region": "eu-west-1",
93
+ "profile": "test",
94
+ "defaults": {
95
+ "alerts": {
96
+ "debug": "hello@gmail.com"
97
+ }
98
+ }
99
+ }
100
+ ```
101
+
102
+ ๐Ÿ”‘ Key Fields
103
+
104
+ - name: Name of your application.
105
+
106
+ - region: AWS region where you want to deploy your infrastructure.
107
+
108
+ - profile: Your AWS CLI profile to use for deployment.
109
+
110
+ ### Modular Stacks
111
+
112
+ Each feature/module of your application can be defined as a separate stack file. These live in their own folders and are completely independent.
113
+
114
+ Example - `auth/stack.json`
115
+
116
+ ```
117
+ {
118
+ "name": "auth",
119
+ "functions": {
120
+ "verify": "./src/lambda.ts" // AWS Lambda
121
+ },
122
+
123
+ }
124
+ ```
125
+
126
+ Example - `rate/stack.json`
127
+
128
+ ```
129
+ {
130
+ "name": "rate",
131
+ "functions": {
132
+ "limit": "./src/lambda.ts" // AWS Lambda
133
+ },
134
+
135
+ }
136
+ ```
137
+
138
+ You can create as many stack files as needed, each targeting different parts of your application.
139
+
140
+ ### Deploying
141
+
142
+ Deploy all stacks
143
+
144
+ ```bash
145
+ $ pnpm awsless deploy
146
+ ```
147
+
148
+ Deploy individual stack
149
+
150
+ ```bash
151
+ $ pnpm awsless deploy rate
152
+ ```
153
+
154
+ Deploy multiple stacks
155
+
156
+ ```bash
157
+ $ pnpm awsless deploy rate auth
158
+ ```
159
+
160
+ Deploy base stack
161
+
162
+ ```bash
163
+ $ pnpm awsless deploy base
164
+ ```
165
+
166
+ ### Stack Updates
167
+
168
+ Awsless makes it simple to remove infrastructure when it's no longer needed.
169
+
170
+ ๐Ÿงผ Delete a Specific Stack
171
+
172
+ ```bash
173
+ $ pnpm awsless delete rate
174
+ ```
175
+
176
+ ๐Ÿ’ฃ Delete All Stacks
177
+
178
+ ```bash
179
+ pnpm awsless delete
180
+ ```
181
+
182
+ โš ๏ธ This will remove all deployed resources associated with your stacks. Use with caution!
183
+
184
+ โ™ป๏ธ Updating or Replacing Resources
185
+ When you modify a stack file and run a deployment again, Awsless will:
186
+
187
+ - Update existing resources if changes are detected.
188
+
189
+ - Delete resources that are removed from the stack file.
190
+
191
+ - Create new resources as needed.
192
+
193
+ - This ensures your infrastructure always reflects the current state of your stack configuration โ€” no manual cleanup required.
194
+
195
+ ### Smart Helpers: Call Your Infra Like Functions
196
+
197
+ Once your stacks are defined, Awsless provides built-in helpers like Fn, Queue, and Task to let you interact with your infrastructure directly from your application code โ€” no wiring or manual setup needed.
198
+
199
+ To enable full type support for these resources, run:
200
+
201
+ ```bash
202
+ $ pnpm run dev
203
+ ```
204
+
205
+ This will watch your project and automatically generate type definitions for all the resources you've created.
206
+
207
+ You can then use them seamlessly inside your Lambda functions:
208
+
209
+ Now from one lambda function we can all any infra like
210
+
211
+ ```typescript
212
+ import { Queue, Fn } from 'awsless'
213
+
214
+ // Call a Lambda function from another stack
215
+ await Fn.rate.limit()
216
+
217
+ // Push a message to a queue
218
+ await Queue.notifications.send({ userId: 123 })
219
+ ```
220
+
221
+ ๐Ÿ’ก These helpers are fully typed and auto-wired, making your code clean, safe, and easy to maintain.
222
+
223
+ ## Testing Stacks
224
+
225
+ Awsless supports built-in testing for your stacks to ensure everything works as expected before deployment.
226
+
227
+ You can define test folder in each stack
228
+
229
+ ```json
230
+ {
231
+ "name": "rate",
232
+ "test": "./path/to/test/folder"
233
+ }
234
+ ```
235
+
236
+ exmaple test case
237
+ `rate/test/utils.ts`
238
+
239
+ ```typescript
240
+ describe('test', () => {
241
+ it('hello world', async () => {
242
+ expect(1 + 2).toStrictEqual(3)
243
+ })
244
+ })
245
+ ```
246
+
247
+ ๐Ÿ” Run Tests Manually
248
+
249
+ ```bash
250
+ $ pnpm awsless test rate
251
+ ```
252
+
253
+ This will look for a defined test folder inside the rate stack directory and run any defined tests inside here.
254
+
255
+ ๐Ÿ›ก๏ธ Tests Run Automatically Before Deploy
256
+ Whenever you run `pnpm awsless deploy`, Awsless will automatically:
257
+
258
+ - Check if a test/ folder exists for each stack
259
+
260
+ - Run the tests for that stack
261
+
262
+ - Block the deployment if any tests fail
263
+
264
+ ## Core Resources
265
+
266
+ ### Function - AWS Lambda
267
+
268
+ #### Basic usage
269
+
270
+ ```json
271
+ {
272
+ "functions": {
273
+ "FUNCTION_NAME": "/path/to/function"
274
+ }
275
+ }
276
+ ```
277
+
278
+ #### Advanced usage
279
+
280
+ You can also customize your Lambda function with additional parameters like memory size, timeout, environment variables, and more:
281
+
282
+ ```json
283
+ "functions": {
284
+ "test": {
285
+ "code": "/path/to/function",
286
+ "memorySize": 512
287
+ }
288
+ },
289
+ ```
290
+
291
+ ### Task
292
+
293
+ A Task in Awsless is an asynchronous Lambda function designed for background processing. You can trigger a task and immediately move on โ€” Awsless handles the execution in the background, including retries and logging on failure.
294
+
295
+ #### Basic usage
296
+
297
+ ```json
298
+ {
299
+ "tasks": {
300
+ "FUNCTION_NAME": "/path/to/function"
301
+ }
302
+ }
303
+ ```
304
+
305
+ #### Advanced usage
306
+
307
+ You can also customize your Lambda function with additional parameters like memory size, timeout, environment variables, and more:
308
+
309
+ ```json
310
+ "tasks": {
311
+ "test": {
312
+ "code": "/path/to/function",
313
+ "memorySize": 512
314
+ }
315
+ },
316
+ ```
317
+
318
+ ### Table
319
+
320
+ The tables feature in Awsless allows you to define fully managed, serverless DynamoDB tables directly in your stack configuration.
321
+
322
+ #### Usage
323
+
324
+ ```json
325
+ {
326
+ "tables": {
327
+ "TABLE_NAME": {
328
+ "hash": "id",
329
+ "sort": "user",
330
+ "indexes": {
331
+ "list": {
332
+ "hash": "createdAt",
333
+ "sort": "id"
334
+ }
335
+ }
336
+ }
337
+ }
338
+ }
339
+ ```
340
+
341
+ ๐Ÿ”‘ Key Fields:
342
+
343
+ - `hash` - Primary key
344
+ - `sort` - Sort key
345
+ - `indexes` - Define secondary index here
346
+
347
+ ### Queue
348
+
349
+ This allows you to define a queue along with the consumer lambda.
350
+
351
+ #### Usage
352
+
353
+ ```json
354
+ {
355
+ "queues": {
356
+ "sendMail": {
357
+ "consumer": "/path/to/lambda/file",
358
+ "maxConcurrency": 2,
359
+ "batchSize": 5
360
+ }
361
+ }
362
+ }
363
+ ```
364
+
365
+ ### Topics
366
+
367
+ This allows you to define a topic along with the subscriber lambda.
368
+
369
+ #### Usage
370
+
371
+ ```json
372
+ {
373
+ {
374
+ "topics": [ "TOPIC_NAME" ],
375
+ "subscribers": {
376
+ "TOPIC_NAME": "topic-consumer.ts",
377
+ }
378
+ }
379
+ }
380
+ ```
381
+
382
+ ### Crons
383
+
384
+ Awsless uses AWS EventBridge to provide fully managed, serverless cron jobs โ€” perfect for running scheduled tasks like cleanups, reports, or recurring syncs.
385
+
386
+ #### Usage
387
+
388
+ ```json
389
+ {
390
+ "crons": {
391
+ "CRON_NAME": {
392
+ "schedule": "1 day",
393
+ "consumer": "cron-consumer.ts"
394
+ }
395
+ }
396
+ }
397
+ ```
398
+
399
+ ๐Ÿ”‘ Key Options:
400
+
401
+ - `schedule`: The interval or cron expression to define when the job should run (e.g., "1 day" or "cron(0 12 \* _ ? _)").
402
+
403
+ - `consumer`: Path to the Lambda function that should be triggered on schedule.
404
+
405
+ #### RPC
406
+
407
+ Awsless allows you to easily expose any Lambda function as a type-safe RPC (Remote Procedure Call) endpoint for your frontend.
408
+
409
+ The request and response types are automatically inferred from your Lambda function's payload and return value, giving you end-to-end type safety.
410
+
411
+ ```json
412
+ {
413
+ "rpc": {
414
+ "base": {
415
+ // base resource defined in app.json
416
+ "SendFriendRequest": "/path/to/lambda"
417
+ }
418
+ }
419
+ }
420
+ ```
421
+
422
+ ## Smart Functions - Call your infra from code
423
+
424
+ With awsless, you can interact with your infrastructure directly from your code. awsless generates all necessary types for you, allowing seamless access to your resources.
425
+
426
+ To set up, define your stacks and run:
427
+
428
+ ```bash
429
+ $ pnpm awsless dev
430
+ ```
431
+
432
+ This command will generate the required types and mappings, enabling you to access infrastructure components in your code effortlessly.
433
+
434
+ Resources are accessible via their stack name and resource name.
435
+ For instance, if a Lambda function exists within a stack named player, you can access its resources using:
436
+
437
+ `player.{resourceName}`
438
+
439
+ ### Examples
440
+
441
+ #### Lambda Function
442
+
443
+ Calling a function named `limit` inside the `rate` stack:
444
+
445
+ ```typescript
446
+ import { Fn } from 'awsless'
447
+
448
+ await Fn.rate.limit({ userId: 'test' })
449
+ ```
450
+
451
+ #### Task
452
+
453
+ ```typescript
454
+ import { Task } from 'awsless'
455
+
456
+ await Task.mail.send({ msg: 'hi', userId: 'test' })
457
+ ```
458
+
459
+ #### Queue
460
+
461
+ Sending a message to a queue
462
+
463
+ ```typescript
464
+ import { Queue } from 'awsless'
465
+
466
+ await Queue.mail.send({ msg: 'hi', userId: 'test' })
467
+ ```
468
+
469
+ #### Topic
470
+
471
+ Publish a message to SNS topic
472
+
473
+ ```typescript
474
+ import { Topic } from 'awsless'
475
+
476
+ await Topic.transaction.credit({ amount: 10, userId: 'test' })
477
+ ```
478
+
479
+ #### Config
480
+
481
+ Reading a secret configuration value:
482
+
483
+ ```typescript
484
+ import { Config } from 'awsless'
485
+
486
+ const key = await Config.API_KEY
487
+ ```