@awsless/cli 0.0.46-next.11 → 0.0.46-next.12
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/dist/bin.js +126 -22
- package/package.json +11 -11
- package/README.MD +0 -487
package/dist/bin.js
CHANGED
|
@@ -172965,6 +172965,117 @@ var zipFiles = (files) => {
|
|
|
172965
172965
|
});
|
|
172966
172966
|
};
|
|
172967
172967
|
|
|
172968
|
+
// src/feature/bundle/policy.ts
|
|
172969
|
+
var compactPolicyStatements = (statements) => {
|
|
172970
|
+
const merged = mergeEqualStatements(statements);
|
|
172971
|
+
const absorbed = merged.map(absorbWildcardResources);
|
|
172972
|
+
return mergeConditionValues(absorbed);
|
|
172973
|
+
};
|
|
172974
|
+
var mergeEqualStatements = (statements) => {
|
|
172975
|
+
const groups = new Map;
|
|
172976
|
+
for (const statement of statements) {
|
|
172977
|
+
const key = JSON.stringify([
|
|
172978
|
+
statement.effect ?? "allow",
|
|
172979
|
+
[...statement.actions].sort(),
|
|
172980
|
+
statement.conditions ?? null
|
|
172981
|
+
]);
|
|
172982
|
+
const group4 = groups.get(key);
|
|
172983
|
+
if (!group4) {
|
|
172984
|
+
groups.set(key, { ...statement, resources: [...statement.resources] });
|
|
172985
|
+
continue;
|
|
172986
|
+
}
|
|
172987
|
+
for (const resource of statement.resources) {
|
|
172988
|
+
if (!group4.resources.includes(resource)) {
|
|
172989
|
+
group4.resources.push(resource);
|
|
172990
|
+
}
|
|
172991
|
+
}
|
|
172992
|
+
}
|
|
172993
|
+
return Array.from(groups.values());
|
|
172994
|
+
};
|
|
172995
|
+
var absorbWildcardResources = (statement) => {
|
|
172996
|
+
const prefixes = statement.resources.filter((resource) => {
|
|
172997
|
+
return resource.endsWith("*") && !resource.slice(0, -1).includes("*") && !resource.includes("?");
|
|
172998
|
+
}).map((resource) => resource.slice(0, -1));
|
|
172999
|
+
const resources = statement.resources.filter((resource) => {
|
|
173000
|
+
return !prefixes.some((prefix) => {
|
|
173001
|
+
return resource !== `${prefix}*` && resource.startsWith(prefix);
|
|
173002
|
+
});
|
|
173003
|
+
});
|
|
173004
|
+
return { ...statement, resources };
|
|
173005
|
+
};
|
|
173006
|
+
var mergeConditionValues = (statements) => {
|
|
173007
|
+
const output = [];
|
|
173008
|
+
const groups = new Map;
|
|
173009
|
+
for (const statement of statements) {
|
|
173010
|
+
const condition = singleStringEqualsCondition(statement);
|
|
173011
|
+
if (!condition) {
|
|
173012
|
+
output.push(statement);
|
|
173013
|
+
continue;
|
|
173014
|
+
}
|
|
173015
|
+
const key = JSON.stringify([
|
|
173016
|
+
statement.effect ?? "allow",
|
|
173017
|
+
[...statement.actions].sort(),
|
|
173018
|
+
[...statement.resources].sort(),
|
|
173019
|
+
condition.key
|
|
173020
|
+
]);
|
|
173021
|
+
const group4 = groups.get(key);
|
|
173022
|
+
if (!group4) {
|
|
173023
|
+
const entry = { statement, conditionKey: condition.key, values: [...condition.values] };
|
|
173024
|
+
groups.set(key, entry);
|
|
173025
|
+
output.push(entry);
|
|
173026
|
+
continue;
|
|
173027
|
+
}
|
|
173028
|
+
for (const value of condition.values) {
|
|
173029
|
+
if (!group4.values.includes(value)) {
|
|
173030
|
+
group4.values.push(value);
|
|
173031
|
+
}
|
|
173032
|
+
}
|
|
173033
|
+
}
|
|
173034
|
+
return output.map((entry) => {
|
|
173035
|
+
if (!("conditionKey" in entry)) {
|
|
173036
|
+
return entry;
|
|
173037
|
+
}
|
|
173038
|
+
if (entry.values.length === 1) {
|
|
173039
|
+
return entry.statement;
|
|
173040
|
+
}
|
|
173041
|
+
return {
|
|
173042
|
+
...entry.statement,
|
|
173043
|
+
conditions: {
|
|
173044
|
+
StringEquals: {
|
|
173045
|
+
[entry.conditionKey]: entry.values
|
|
173046
|
+
}
|
|
173047
|
+
}
|
|
173048
|
+
};
|
|
173049
|
+
});
|
|
173050
|
+
};
|
|
173051
|
+
var singleStringEqualsCondition = (statement) => {
|
|
173052
|
+
const conditions = statement.conditions;
|
|
173053
|
+
if (typeof conditions !== "object" || conditions === null) {
|
|
173054
|
+
return;
|
|
173055
|
+
}
|
|
173056
|
+
const operators = Object.keys(conditions);
|
|
173057
|
+
if (operators.length !== 1 || operators[0] !== "StringEquals") {
|
|
173058
|
+
return;
|
|
173059
|
+
}
|
|
173060
|
+
const values = conditions.StringEquals;
|
|
173061
|
+
if (typeof values !== "object" || values === null) {
|
|
173062
|
+
return;
|
|
173063
|
+
}
|
|
173064
|
+
const keys = Object.keys(values);
|
|
173065
|
+
const key = keys[0];
|
|
173066
|
+
if (keys.length !== 1 || !key) {
|
|
173067
|
+
return;
|
|
173068
|
+
}
|
|
173069
|
+
const value = values[key];
|
|
173070
|
+
if (typeof value === "string") {
|
|
173071
|
+
return { key, values: [value] };
|
|
173072
|
+
}
|
|
173073
|
+
if (Array.isArray(value) && value.every((entry) => typeof entry === "string")) {
|
|
173074
|
+
return { key, values: value };
|
|
173075
|
+
}
|
|
173076
|
+
return;
|
|
173077
|
+
};
|
|
173078
|
+
|
|
172968
173079
|
// src/feature/bundle/util.ts
|
|
172969
173080
|
import { generateFileHash } from "@awsless/ts-file-cache";
|
|
172970
173081
|
import { createHash as createHash13 } from "crypto";
|
|
@@ -173510,7 +173621,7 @@ var bundleFeature = defineFeature({
|
|
|
173510
173621
|
const list2 = await resolveInputs(Array.from(statements));
|
|
173511
173622
|
resolve3(JSON.stringify({
|
|
173512
173623
|
Version: "2012-10-17",
|
|
173513
|
-
Statement: list2.map((statement) => ({
|
|
173624
|
+
Statement: compactPolicyStatements(list2).map((statement) => ({
|
|
173514
173625
|
Effect: pascalCase(statement.effect ?? "allow"),
|
|
173515
173626
|
Action: statement.actions,
|
|
173516
173627
|
Resource: statement.resources,
|
|
@@ -173658,7 +173769,8 @@ var bundleFeature = defineFeature({
|
|
|
173658
173769
|
addHandler,
|
|
173659
173770
|
addEnv,
|
|
173660
173771
|
addLayer,
|
|
173661
|
-
addPermission
|
|
173772
|
+
addPermission,
|
|
173773
|
+
statements
|
|
173662
173774
|
});
|
|
173663
173775
|
}
|
|
173664
173776
|
});
|
|
@@ -181759,17 +181871,6 @@ var configFeature = defineFeature({
|
|
|
181759
181871
|
ctx.registerConfig(name);
|
|
181760
181872
|
ctx.addEnv(`CONFIG_${constantCase(name)}`, name);
|
|
181761
181873
|
}
|
|
181762
|
-
if (configs.length) {
|
|
181763
|
-
ctx.addGlobalPermission({
|
|
181764
|
-
actions: [
|
|
181765
|
-
"ssm:GetParameter",
|
|
181766
|
-
"ssm:GetParameters",
|
|
181767
|
-
"ssm:GetParametersByPath",
|
|
181768
|
-
"ssm:GetParameterHistory"
|
|
181769
|
-
],
|
|
181770
|
-
resources: configs.map((name) => `arn:aws:ssm:${ctx.appConfig.region}:${ctx.accountId}:parameter${configParameterPrefix(ctx.app.name)}/${kebabCase(name)}`)
|
|
181771
|
-
});
|
|
181772
|
-
}
|
|
181773
181874
|
}
|
|
181774
181875
|
});
|
|
181775
181876
|
|
|
@@ -185766,16 +185867,19 @@ var metricFeature = defineFeature({
|
|
|
185766
185867
|
onStack(ctx) {
|
|
185767
185868
|
const bundle = ctx.shared.get("bundle", "main");
|
|
185768
185869
|
const namespace = `awsless/${kebabCase(ctx.app.name)}/${kebabCase(ctx.stack.name)}`;
|
|
185769
|
-
ctx.
|
|
185770
|
-
|
|
185771
|
-
|
|
185772
|
-
|
|
185773
|
-
|
|
185774
|
-
|
|
185870
|
+
const metrics = Object.entries(ctx.stackConfig.metrics ?? {});
|
|
185871
|
+
if (metrics.length > 0) {
|
|
185872
|
+
ctx.addGlobalPermission({
|
|
185873
|
+
actions: ["cloudwatch:PutMetricData"],
|
|
185874
|
+
resources: ["*"],
|
|
185875
|
+
conditions: {
|
|
185876
|
+
StringEquals: {
|
|
185877
|
+
"cloudwatch:namespace": namespace
|
|
185878
|
+
}
|
|
185775
185879
|
}
|
|
185776
|
-
}
|
|
185777
|
-
}
|
|
185778
|
-
for (const [id, props] of
|
|
185880
|
+
});
|
|
185881
|
+
}
|
|
185882
|
+
for (const [id, props] of metrics) {
|
|
185779
185883
|
const group4 = new Group(ctx.stack, "metric", id);
|
|
185780
185884
|
ctx.addEnv(`METRIC_${constantCase(ctx.stack.name)}_${constantCase(id)}`, props.type);
|
|
185781
185885
|
for (const alarmId in props.alarms ?? []) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/cli",
|
|
3
|
-
"version": "0.0.46-next.
|
|
3
|
+
"version": "0.0.46-next.12",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"@awsless/lambda": "^0.0.46",
|
|
32
32
|
"@awsless/s3": "^0.0.22",
|
|
33
33
|
"@awsless/validate": "^0.1.7",
|
|
34
|
-
"
|
|
35
|
-
"awsless": "^0.0.
|
|
34
|
+
"awsless": "^0.0.15-next.2",
|
|
35
|
+
"@awsless/weak-cache": "^0.0.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@aws-sdk/client-cloudformation": "^3.369.0",
|
|
@@ -100,25 +100,25 @@
|
|
|
100
100
|
"zip-a-folder": "^3.1.6",
|
|
101
101
|
"zod": "^3.24.2",
|
|
102
102
|
"zod-to-json-schema": "^3.24.3",
|
|
103
|
-
"@awsless/clui": "^0.0.9",
|
|
104
|
-
"@awsless/duration": "^0.0.4",
|
|
105
103
|
"@awsless/big-float": "^0.1.7",
|
|
106
104
|
"@awsless/cloudwatch": "^0.0.1",
|
|
105
|
+
"@awsless/clui": "^0.0.9",
|
|
106
|
+
"@awsless/duration": "^0.0.4",
|
|
107
107
|
"@awsless/dynamodb": "^0.3.21",
|
|
108
|
-
"@awsless/json": "^0.0.11",
|
|
109
108
|
"@awsless/iot": "^0.0.5",
|
|
110
109
|
"@awsless/lambda": "^0.0.46",
|
|
111
|
-
"@awsless/
|
|
112
|
-
"@awsless/redis": "^0.1.13",
|
|
113
|
-
"@awsless/s3": "^0.0.22",
|
|
110
|
+
"@awsless/json": "^0.0.11",
|
|
114
111
|
"@awsless/scheduler": "^0.0.5",
|
|
112
|
+
"@awsless/s3": "^0.0.22",
|
|
113
|
+
"@awsless/redis": "^0.1.13",
|
|
115
114
|
"@awsless/sns": "^0.0.11",
|
|
115
|
+
"@awsless/size": "^0.0.2",
|
|
116
116
|
"@awsless/sqs": "^0.0.24",
|
|
117
|
-
"@awsless/ssm": "^0.0.8",
|
|
118
117
|
"@awsless/validate": "^0.1.7",
|
|
119
118
|
"@awsless/weak-cache": "^0.0.1",
|
|
119
|
+
"@awsless/ssm": "^0.0.8",
|
|
120
120
|
"awsless": "^0.0.15-next.2",
|
|
121
|
-
"@awsless/
|
|
121
|
+
"@awsless/open-search": "^0.0.24"
|
|
122
122
|
},
|
|
123
123
|
"scripts": {
|
|
124
124
|
"test": "bun cli/build-handlers.ts && pnpm vitest",
|
package/README.MD
DELETED
|
@@ -1,487 +0,0 @@
|
|
|
1
|
-
<p align="center">Awsless - Infrastructure as a code</p>
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.org/package/@awsless/awsless)
|
|
6
|
-
|
|
7
|
-
[](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
|
-
```
|