@awsless/awsless 0.0.582 → 0.0.584

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 CHANGED
@@ -13,37 +13,37 @@
13
13
  - [Table of Contents](#table-of-contents)
14
14
  - [Features](#features)
15
15
  - [Installing](#installing)
16
- - [Package manager](#package-manager)
16
+ - [Package manager](#package-manager)
17
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)
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
23
  - [Testing Stacks](#testing-stacks)
24
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)
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
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)
41
+ - [Examples](#examples)
42
+ - [Lambda Function](#lambda-function)
43
+ - [Task](#task-1)
44
+ - [Queue](#queue-1)
45
+ - [Topic](#topic)
46
+ - [Config](#config)
47
47
 
48
48
  ## Features
49
49
 
@@ -61,7 +61,6 @@
61
61
 
62
62
  🔄 Types generatation for all resources that can be acessed anywhere in the code
63
63
 
64
-
65
64
  ## Installing
66
65
 
67
66
  ### Package manager
@@ -72,21 +71,21 @@ Using npm:
72
71
  $ npm i @awsless/awsless
73
72
  ```
74
73
 
75
-
76
74
  Using pnpm:
77
75
 
78
76
  ```bash
79
77
  $ pnpm i @awsless/awsless
80
78
  ```
81
79
 
82
-
83
80
  ## Getting Started
84
- 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.
85
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.
86
83
 
87
84
  ### Base Configuration
85
+
88
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.
89
87
  `app.json`
88
+
90
89
  ```
91
90
  {
92
91
  "name": "hello-world",
@@ -99,19 +98,21 @@ This is your shared app configuration, which acts as the base stack for the enti
99
98
  }
100
99
  }
101
100
  ```
102
- 🔑 Key Fields
103
- * name: Name of your application.
104
101
 
105
- * region: AWS region where you want to deploy your infrastructure.
102
+ 🔑 Key Fields
106
103
 
107
- * profile: Your AWS CLI profile to use for deployment.
104
+ - name: Name of your application.
108
105
 
106
+ - region: AWS region where you want to deploy your infrastructure.
109
107
 
108
+ - profile: Your AWS CLI profile to use for deployment.
110
109
 
111
110
  ### Modular Stacks
111
+
112
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
113
 
114
114
  Example - `auth/stack.json`
115
+
115
116
  ```
116
117
  {
117
118
  "name": "auth",
@@ -123,6 +124,7 @@ Example - `auth/stack.json`
123
124
  ```
124
125
 
125
126
  Example - `rate/stack.json`
127
+
126
128
  ```
127
129
  {
128
130
  "name": "rate",
@@ -137,66 +139,76 @@ You can create as many stack files as needed, each targeting different parts of
137
139
 
138
140
  ### Deploying
139
141
 
140
-
141
142
  Deploy all stacks
143
+
142
144
  ```bash
143
145
  $ pnpm awsless deploy
144
146
  ```
145
147
 
146
148
  Deploy individual stack
149
+
147
150
  ```bash
148
151
  $ pnpm awsless deploy rate
149
152
  ```
150
153
 
151
154
  Deploy multiple stacks
155
+
152
156
  ```bash
153
157
  $ pnpm awsless deploy rate auth
154
158
  ```
155
159
 
156
160
  Deploy base stack
161
+
157
162
  ```bash
158
163
  $ pnpm awsless deploy base
159
164
  ```
160
165
 
161
166
  ### Stack Updates
167
+
162
168
  Awsless makes it simple to remove infrastructure when it's no longer needed.
163
169
 
164
170
  🧼 Delete a Specific Stack
171
+
165
172
  ```bash
166
173
  $ pnpm awsless delete rate
167
174
  ```
168
175
 
169
176
  💣 Delete All Stacks
177
+
170
178
  ```bash
171
179
  pnpm awsless delete
172
180
  ```
181
+
173
182
  ⚠️ This will remove all deployed resources associated with your stacks. Use with caution!
174
183
 
175
184
  ♻️ Updating or Replacing Resources
176
185
  When you modify a stack file and run a deployment again, Awsless will:
177
186
 
178
- * Update existing resources if changes are detected.
187
+ - Update existing resources if changes are detected.
179
188
 
180
- * Delete resources that are removed from the stack file.
189
+ - Delete resources that are removed from the stack file.
181
190
 
182
- * Create new resources as needed.
191
+ - Create new resources as needed.
183
192
 
184
- * This ensures your infrastructure always reflects the current state of your stack configuration — no manual cleanup required.
193
+ - This ensures your infrastructure always reflects the current state of your stack configuration — no manual cleanup required.
185
194
 
186
195
  ### Smart Helpers: Call Your Infra Like Functions
196
+
187
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.
188
198
 
189
199
  To enable full type support for these resources, run:
200
+
190
201
  ```bash
191
202
  $ pnpm run dev
192
203
  ```
204
+
193
205
  This will watch your project and automatically generate type definitions for all the resources you've created.
194
206
 
195
207
  You can then use them seamlessly inside your Lambda functions:
196
208
 
197
209
  Now from one lambda function we can all any infra like
198
- ```typescript
199
210
 
211
+ ```typescript
200
212
  import { Queue, Fn } from '@awsless/awsless'
201
213
 
202
214
  // Call a Lambda function from another stack
@@ -205,23 +217,25 @@ await Fn.rate.limit()
205
217
  // Push a message to a queue
206
218
  await Queue.notifications.send({ userId: 123 })
207
219
  ```
208
- 💡 These helpers are fully typed and auto-wired, making your code clean, safe, and easy to maintain.
209
-
210
220
 
221
+ 💡 These helpers are fully typed and auto-wired, making your code clean, safe, and easy to maintain.
211
222
 
212
223
  ## Testing Stacks
224
+
213
225
  Awsless supports built-in testing for your stacks to ensure everything works as expected before deployment.
214
226
 
215
227
  You can define test folder in each stack
228
+
216
229
  ```json
217
230
  {
218
- "name": "rate",
219
- "test": "./path/to/test/folder"
231
+ "name": "rate",
232
+ "test": "./path/to/test/folder"
220
233
  }
221
234
  ```
222
235
 
223
236
  exmaple test case
224
237
  `rate/test/utils.ts`
238
+
225
239
  ```typescript
226
240
  describe('test', () => {
227
241
  it('hello world', async () => {
@@ -231,6 +245,7 @@ describe('test', () => {
231
245
  ```
232
246
 
233
247
  🔍 Run Tests Manually
248
+
234
249
  ```bash
235
250
  $ pnpm awsless test rate
236
251
  ```
@@ -240,27 +255,30 @@ This will look for a defined test folder inside the rate stack directory and run
240
255
  🛡️ Tests Run Automatically Before Deploy
241
256
  Whenever you run `pnpm awsless deploy`, Awsless will automatically:
242
257
 
243
- * Check if a test/ folder exists for each stack
258
+ - Check if a test/ folder exists for each stack
244
259
 
245
- * Run the tests for that stack
260
+ - Run the tests for that stack
246
261
 
247
- * Block the deployment if any tests fail
262
+ - Block the deployment if any tests fail
248
263
 
249
264
  ## Core Resources
250
265
 
251
266
  ### Function - AWS Lambda
267
+
252
268
  #### Basic usage
269
+
253
270
  ```json
254
271
  {
255
- "functions": {
256
- "FUNCTION_NAME": "/path/to/function"
257
- }
272
+ "functions": {
273
+ "FUNCTION_NAME": "/path/to/function"
274
+ }
258
275
  }
259
276
  ```
260
277
 
261
278
  #### Advanced usage
262
279
 
263
280
  You can also customize your Lambda function with additional parameters like memory size, timeout, environment variables, and more:
281
+
264
282
  ```json
265
283
  "functions": {
266
284
  "test": {
@@ -271,21 +289,23 @@ You can also customize your Lambda function with additional parameters like memo
271
289
  ```
272
290
 
273
291
  ### Task
274
- 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.
275
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.
276
294
 
277
295
  #### Basic usage
296
+
278
297
  ```json
279
298
  {
280
- "tasks": {
281
- "FUNCTION_NAME": "/path/to/function"
282
- }
299
+ "tasks": {
300
+ "FUNCTION_NAME": "/path/to/function"
301
+ }
283
302
  }
284
303
  ```
285
304
 
286
305
  #### Advanced usage
287
306
 
288
307
  You can also customize your Lambda function with additional parameters like memory size, timeout, environment variables, and more:
308
+
289
309
  ```json
290
310
  "tasks": {
291
311
  "test": {
@@ -296,54 +316,58 @@ You can also customize your Lambda function with additional parameters like memo
296
316
  ```
297
317
 
298
318
  ### Table
299
- The tables feature in Awsless allows you to define fully managed, serverless DynamoDB tables directly in your stack configuration.
300
319
 
320
+ The tables feature in Awsless allows you to define fully managed, serverless DynamoDB tables directly in your stack configuration.
301
321
 
302
322
  #### Usage
323
+
303
324
  ```json
304
325
  {
305
- "tables": {
306
- "TABLE_NAME": {
307
- "hash": "id",
308
- "sort": "user",
309
- "indexes": {
326
+ "tables": {
327
+ "TABLE_NAME": {
328
+ "hash": "id",
329
+ "sort": "user",
330
+ "indexes": {
310
331
  "list": {
311
332
  "hash": "createdAt",
312
333
  "sort": "id"
313
334
  }
314
- },
315
- }
316
- }
335
+ }
336
+ }
337
+ }
317
338
  }
318
339
  ```
319
340
 
320
341
  🔑 Key Fields:
321
- * `hash` - Primary key
322
- * `sort` - Sort key
323
- * `indexes` - Define secondary index here
324
342
 
343
+ - `hash` - Primary key
344
+ - `sort` - Sort key
345
+ - `indexes` - Define secondary index here
325
346
 
326
347
  ### Queue
348
+
327
349
  This allows you to define a queue along with the consumer lambda.
328
350
 
329
351
  #### Usage
352
+
330
353
  ```json
331
354
  {
332
355
  "queues": {
333
356
  "sendMail": {
334
357
  "consumer": "/path/to/lambda/file",
335
358
  "maxConcurrency": 2,
336
- "batchSize": 5,
359
+ "batchSize": 5
337
360
  }
338
- },
361
+ }
339
362
  }
340
363
  ```
341
364
 
342
-
343
365
  ### Topics
366
+
344
367
  This allows you to define a topic along with the subscriber lambda.
345
368
 
346
369
  #### Usage
370
+
347
371
  ```json
348
372
  {
349
373
  {
@@ -356,42 +380,47 @@ This allows you to define a topic along with the subscriber lambda.
356
380
  ```
357
381
 
358
382
  ### Crons
383
+
359
384
  Awsless uses AWS EventBridge to provide fully managed, serverless cron jobs — perfect for running scheduled tasks like cleanups, reports, or recurring syncs.
360
385
 
361
386
  #### Usage
387
+
362
388
  ```json
363
389
  {
364
- "crons": {
365
- "CRON_NAME": {
366
- "schedule": "1 day",
367
- "consumer": "cron-consumer.ts",
368
- }
369
- }
390
+ "crons": {
391
+ "CRON_NAME": {
392
+ "schedule": "1 day",
393
+ "consumer": "cron-consumer.ts"
394
+ }
395
+ }
370
396
  }
371
397
  ```
372
398
 
373
399
  🔑 Key Options:
374
- * `schedule`: The interval or cron expression to define when the job should run (e.g., "1 day" or "cron(0 12 * * ? *)").
375
400
 
376
- * `consumer`: Path to the Lambda function that should be triggered on schedule.
401
+ - `schedule`: The interval or cron expression to define when the job should run (e.g., "1 day" or "cron(0 12 \* _ ? _)").
377
402
 
403
+ - `consumer`: Path to the Lambda function that should be triggered on schedule.
378
404
 
379
405
  #### RPC
406
+
380
407
  Awsless allows you to easily expose any Lambda function as a type-safe RPC (Remote Procedure Call) endpoint for your frontend.
381
408
 
382
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.
383
410
 
384
411
  ```json
385
412
  {
386
- "rpc": {
387
- "base": { // base resource defined in app.json
388
- "SendFriendRequest": "/path/to/lambda"
389
- }
390
- }
413
+ "rpc": {
414
+ "base": {
415
+ // base resource defined in app.json
416
+ "SendFriendRequest": "/path/to/lambda"
417
+ }
418
+ }
391
419
  }
392
420
  ```
393
421
 
394
422
  ## Smart Functions - Call your infra from code
423
+
395
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.
396
425
 
397
426
  To set up, define your stacks and run:
@@ -407,7 +436,6 @@ For instance, if a Lambda function exists within a stack named player, you can a
407
436
 
408
437
  `player.{resourceName}`
409
438
 
410
-
411
439
  ### Examples
412
440
 
413
441
  #### Lambda Function
@@ -417,37 +445,39 @@ Calling a function named `limit` inside the `rate` stack:
417
445
  ```typescript
418
446
  import { Fn } from '@awsless/awsless'
419
447
 
420
- await Fn.rate.limit({userId: "test"})
448
+ await Fn.rate.limit({ userId: 'test' })
421
449
  ```
422
450
 
423
-
424
451
  #### Task
425
452
 
426
453
  ```typescript
427
454
  import { Task } from '@awsless/awsless'
428
455
 
429
- await Task.mail.send({msg: "hi", userId: "test"})
456
+ await Task.mail.send({ msg: 'hi', userId: 'test' })
430
457
  ```
431
458
 
432
459
  #### Queue
460
+
433
461
  Sending a message to a queue
462
+
434
463
  ```typescript
435
464
  import { Queue } from '@awsless/awsless'
436
465
 
437
- await Queue.mail.send({msg: "hi", userId: "test"})
466
+ await Queue.mail.send({ msg: 'hi', userId: 'test' })
438
467
  ```
439
468
 
440
-
441
469
  #### Topic
470
+
442
471
  Publish a message to SNS topic
443
472
 
444
473
  ```typescript
445
474
  import { Topic } from '@awsless/awsless'
446
475
 
447
- await Topic.transaction.credit({amount: 10, userId: "test"})
476
+ await Topic.transaction.credit({ amount: 10, userId: 'test' })
448
477
  ```
449
478
 
450
479
  #### Config
480
+
451
481
  Reading a secret configuration value:
452
482
 
453
483
  ```typescript