local-serverless-stack 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.
- package/CHANGELOG.md +104 -0
- package/LICENSE +21 -0
- package/README.md +653 -0
- package/bin/cli.js +204 -0
- package/dist/server/dev/dynamo-proxy.d.ts +3 -0
- package/dist/server/dev/dynamo-proxy.d.ts.map +1 -0
- package/dist/server/dev/dynamo-proxy.js +35 -0
- package/dist/server/dev/dynamo-proxy.js.map +1 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +67 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/routes/resources.d.ts +3 -0
- package/dist/server/routes/resources.d.ts.map +1 -0
- package/dist/server/routes/resources.js +16 -0
- package/dist/server/routes/resources.js.map +1 -0
- package/dist/server/routes/services.d.ts +5 -0
- package/dist/server/routes/services.d.ts.map +1 -0
- package/dist/server/routes/services.js +217 -0
- package/dist/server/routes/services.js.map +1 -0
- package/dist/server/services/cache-manager.d.ts +21 -0
- package/dist/server/services/cache-manager.d.ts.map +1 -0
- package/dist/server/services/cache-manager.js +70 -0
- package/dist/server/services/cache-manager.js.map +1 -0
- package/dist/server/services/cloudformation-parser.d.ts +88 -0
- package/dist/server/services/cloudformation-parser.d.ts.map +1 -0
- package/dist/server/services/cloudformation-parser.js +112 -0
- package/dist/server/services/cloudformation-parser.js.map +1 -0
- package/dist/server/services/localstack-manager.d.ts +23 -0
- package/dist/server/services/localstack-manager.d.ts.map +1 -0
- package/dist/server/services/localstack-manager.js +142 -0
- package/dist/server/services/localstack-manager.js.map +1 -0
- package/dist/server/services/process-manager.d.ts +41 -0
- package/dist/server/services/process-manager.d.ts.map +1 -0
- package/dist/server/services/process-manager.js +119 -0
- package/dist/server/services/process-manager.js.map +1 -0
- package/dist/server/services/resource-provisioner.d.ts +37 -0
- package/dist/server/services/resource-provisioner.d.ts.map +1 -0
- package/dist/server/services/resource-provisioner.js +539 -0
- package/dist/server/services/resource-provisioner.js.map +1 -0
- package/dist/ui/assets/index-7WT0rkfU.css +1 -0
- package/dist/ui/assets/index-M0lXeUj-.js +19 -0
- package/dist/ui/index.html +16 -0
- package/package.json +89 -0
- package/packages/serverless-plugin/README.md +95 -0
- package/packages/serverless-plugin/dist/index.d.ts +2 -0
- package/packages/serverless-plugin/dist/index.d.ts.map +1 -0
- package/packages/serverless-plugin/dist/index.js +88 -0
- package/packages/serverless-plugin/dist/index.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
# Local Serverless Stack (LSS)
|
|
2
|
+
|
|
3
|
+
**Local control plane for serverless development with LocalStack orchestration**
|
|
4
|
+
|
|
5
|
+
LSS provides a unified local development environment for serverless microservices, eliminating the need to run separate LocalStack instances for each service.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Centralized LocalStack**: Single LocalStack instance manages DynamoDB, SQS, SNS, and Lambda
|
|
10
|
+
- **Auto-provisioning**: Parses CloudFormation templates from `sls package` and provisions resources automatically
|
|
11
|
+
- **Event source mappings**: Automatically connects SQS queues to Lambda handlers via LocalStack
|
|
12
|
+
- **Lambda proxies**: Generated proxy functions forward events to serverless-offline invoke endpoints
|
|
13
|
+
- **Web UI**: Vue 3 dashboard to monitor services, resources, and event mappings
|
|
14
|
+
- **Hot reload**: Watch for code changes and auto-rebuild/reprovision
|
|
15
|
+
- **Process management**: Start/stop microservices from the orchestrator
|
|
16
|
+
- **CLI Tool**: Simple commands to manage the orchestrator (start/stop/status/logs)
|
|
17
|
+
|
|
18
|
+
## Architecture
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
local-serverless-stack/
|
|
22
|
+
├── bin/ # CLI executable
|
|
23
|
+
│ └── cli.js # lss command entry point
|
|
24
|
+
├── src/ # Source code
|
|
25
|
+
│ ├── server/ # Express API + services
|
|
26
|
+
│ │ ├── routes/ # API endpoints
|
|
27
|
+
│ │ ├── services/ # Business logic
|
|
28
|
+
│ │ └── dev/ # Dev utilities
|
|
29
|
+
│ └── ui/ # Vue 3 dashboard
|
|
30
|
+
├── packages/
|
|
31
|
+
│ └── serverless-plugin/ # Serverless Framework plugin (published separately)
|
|
32
|
+
├── dist/ # Build output
|
|
33
|
+
│ ├── server/ # Compiled Express app
|
|
34
|
+
│ └── ui/ # Built Vue app
|
|
35
|
+
└── tests/ # Integration tests
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Components**:
|
|
39
|
+
- **CLI** (`bin/cli.js`): Background process management (start/stop/status/logs)
|
|
40
|
+
- **Server** (`src/server/`): Express API + LocalStack orchestration
|
|
41
|
+
- **UI** (`src/ui/`): Vue 3 dashboard for monitoring
|
|
42
|
+
- **Plugin** (`packages/serverless-plugin/`): Auto-registration for Serverless Framework
|
|
43
|
+
- **LocalStack**: Docker container (port 4566) with AWS services
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
### Prerequisites
|
|
48
|
+
|
|
49
|
+
- Node.js >= 18
|
|
50
|
+
- Docker (for LocalStack)
|
|
51
|
+
- Serverless Framework >= 3.0
|
|
52
|
+
|
|
53
|
+
### Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
cd /path/to/local-serverless-stack
|
|
57
|
+
npm install
|
|
58
|
+
npm run build
|
|
59
|
+
npm link
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The `npm link` command makes the `lss` CLI available globally via `npx`.
|
|
63
|
+
|
|
64
|
+
## CLI Commands
|
|
65
|
+
|
|
66
|
+
LSS provides a simple CLI to manage the orchestrator in background mode:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Start the orchestrator in background
|
|
70
|
+
npx lss start
|
|
71
|
+
|
|
72
|
+
# Check if orchestrator is running
|
|
73
|
+
npx lss status
|
|
74
|
+
|
|
75
|
+
# View recent logs
|
|
76
|
+
npx lss logs
|
|
77
|
+
|
|
78
|
+
# Stop the orchestrator
|
|
79
|
+
npx lss stop
|
|
80
|
+
|
|
81
|
+
# Show help
|
|
82
|
+
npx lss help
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### CLI Output
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
$ npx lss start
|
|
89
|
+
🚀 LSS Orchestrator started (PID: 12345)
|
|
90
|
+
📊 Dashboard: http://localhost:3100
|
|
91
|
+
🔧 LocalStack: http://localhost:4566
|
|
92
|
+
📝 Logs: /tmp/lss-orchestrator.log
|
|
93
|
+
✅ Service is running
|
|
94
|
+
|
|
95
|
+
$ npx lss status
|
|
96
|
+
🟢 LSS Orchestrator: RUNNING (PID: 12345)
|
|
97
|
+
📊 Dashboard: http://localhost:3100
|
|
98
|
+
🔧 LocalStack: http://localhost:4566
|
|
99
|
+
📝 Logs: /tmp/lss-orchestrator.log
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Development Mode
|
|
103
|
+
|
|
104
|
+
For active development with hot reload:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm run orchestrator:dev
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
This starts:
|
|
111
|
+
- Orchestrator API on http://localhost:3100
|
|
112
|
+
- LocalStack on http://localhost:4566
|
|
113
|
+
- Web UI at http://localhost:3100
|
|
114
|
+
- Auto-reload on code changes
|
|
115
|
+
|
|
116
|
+
## Integration with Projects
|
|
117
|
+
|
|
118
|
+
### 1. Link LSS to Your Project
|
|
119
|
+
|
|
120
|
+
In your project root:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm link local-serverless-stack
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 2. Install Plugin in Microservices
|
|
127
|
+
|
|
128
|
+
In each microservice directory:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm link lss-serverless-plugin
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 3. Configure serverless.yml
|
|
135
|
+
|
|
136
|
+
Add the plugin to your `serverless.yml`:
|
|
137
|
+
|
|
138
|
+
```yaml
|
|
139
|
+
plugins:
|
|
140
|
+
- serverless-auto-swagger
|
|
141
|
+
- serverless-esbuild
|
|
142
|
+
- serverless-offline
|
|
143
|
+
- serverless-localstack
|
|
144
|
+
- lss-serverless-plugin # Add this line
|
|
145
|
+
|
|
146
|
+
custom:
|
|
147
|
+
orchestrator:
|
|
148
|
+
url: http://localhost:3100 # optional, defaults to this
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 4. Workflow
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# 1. Start LSS Orchestrator
|
|
155
|
+
npx lss start
|
|
156
|
+
|
|
157
|
+
# 2. Package your microservice (auto-registers with LSS)
|
|
158
|
+
cd your-microservice
|
|
159
|
+
npx sls package
|
|
160
|
+
|
|
161
|
+
# 3. Start serverless offline
|
|
162
|
+
npx serverless offline start --host 0.0.0.0 --httpPort 3020 --lambdaPort 13020
|
|
163
|
+
|
|
164
|
+
# 4. Monitor in the dashboard
|
|
165
|
+
open http://localhost:3100
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Now when you send a message to an SQS queue in LocalStack, the orchestrator will:
|
|
169
|
+
1. Detect the event via event source mapping
|
|
170
|
+
2. Invoke the Lambda proxy in LocalStack
|
|
171
|
+
3. Proxy forwards to serverless-offline on the invoke port
|
|
172
|
+
4. Your handler executes
|
|
173
|
+
|
|
174
|
+
## Project Structure
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
local-serverless-stack/
|
|
178
|
+
bin/
|
|
179
|
+
cli.js # CLI implementation (npx lss)
|
|
180
|
+
package.json # Workspace root with bin config
|
|
181
|
+
packages/
|
|
182
|
+
orchestrator/ # Main orchestrator (Express + Vue UI)
|
|
183
|
+
server/ # Backend (TypeScript)
|
|
184
|
+
ui/ # Frontend (Vue 3 + Vite)
|
|
185
|
+
dist/ # Compiled output
|
|
186
|
+
serverless-plugin/ # Serverless Framework plugin
|
|
187
|
+
src/index.ts # Plugin implementation
|
|
188
|
+
dist/ # Compiled plugin
|
|
189
|
+
docs/ # Documentation
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Configuration
|
|
193
|
+
|
|
194
|
+
### Environment Variables
|
|
195
|
+
|
|
196
|
+
- `PORT`: Orchestrator API port (default: 3100)
|
|
197
|
+
- `ENABLE_DYNAMO_PROXY`: Enable DynamoDB proxy on port 8000 (default: false)
|
|
198
|
+
- `DYNAMO_PROXY_PORT`: DynamoDB proxy port (default: 8000)
|
|
199
|
+
|
|
200
|
+
### LocalStack Settings
|
|
201
|
+
|
|
202
|
+
LocalStack is configured with:
|
|
203
|
+
- Services: `dynamodb,sqs,sns,lambda`
|
|
204
|
+
- Persistence: Enabled (volume: `lss-localstack-data`)
|
|
205
|
+
- Lambda executor: `local` (no Docker-in-Docker required)
|
|
206
|
+
- Docker socket: Mounted from host
|
|
207
|
+
|
|
208
|
+
## Development
|
|
209
|
+
|
|
210
|
+
### Build All Packages
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
npm run build
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Build Individual Packages
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# Build orchestrator only
|
|
220
|
+
npm run orchestrator:build
|
|
221
|
+
|
|
222
|
+
# Build plugin only
|
|
223
|
+
npm run plugin:build
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Watch Mode (Development)
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# Orchestrator with hot reload
|
|
230
|
+
npm run orchestrator:dev
|
|
231
|
+
|
|
232
|
+
# Plugin with watch
|
|
233
|
+
cd packages/serverless-plugin
|
|
234
|
+
npm run dev
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Testing
|
|
238
|
+
|
|
239
|
+
LSS includes comprehensive integration tests covering CLI, Orchestrator API, and Plugin functionality.
|
|
240
|
+
|
|
241
|
+
### Quick Start
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# Run all tests
|
|
245
|
+
npm test
|
|
246
|
+
|
|
247
|
+
# Run with coverage
|
|
248
|
+
npm run test:coverage
|
|
249
|
+
|
|
250
|
+
# Run specific test suite
|
|
251
|
+
npm run test:cli
|
|
252
|
+
npm run test:orchestrator
|
|
253
|
+
npm run test:plugin
|
|
254
|
+
|
|
255
|
+
# Watch mode
|
|
256
|
+
npm run test:watch
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Using Test Runner Script
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
# Run all integration tests
|
|
263
|
+
./run-tests.sh
|
|
264
|
+
|
|
265
|
+
# Run specific suite
|
|
266
|
+
./run-tests.sh cli
|
|
267
|
+
./run-tests.sh orchestrator
|
|
268
|
+
./run-tests.sh plugin
|
|
269
|
+
|
|
270
|
+
# Run with coverage
|
|
271
|
+
./run-tests.sh coverage
|
|
272
|
+
|
|
273
|
+
# Watch mode
|
|
274
|
+
./run-tests.sh watch
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Test Coverage
|
|
278
|
+
|
|
279
|
+
The test suite validates:
|
|
280
|
+
|
|
281
|
+
✅ **CLI Commands**
|
|
282
|
+
- `npx lss start` - Orchestrator startup
|
|
283
|
+
- `npx lss stop` - Graceful shutdown
|
|
284
|
+
- `npx lss status` - Status reporting
|
|
285
|
+
- `npx lss logs` - Log viewing
|
|
286
|
+
- `npx lss help` - Help information
|
|
287
|
+
|
|
288
|
+
✅ **Orchestrator API**
|
|
289
|
+
- Service registration
|
|
290
|
+
- Resource provisioning (DynamoDB, SQS, SNS)
|
|
291
|
+
- Lambda proxy creation
|
|
292
|
+
- Event source mappings
|
|
293
|
+
- Error handling
|
|
294
|
+
|
|
295
|
+
✅ **Serverless Plugin**
|
|
296
|
+
- CloudFormation parsing
|
|
297
|
+
- Resource creation in LocalStack
|
|
298
|
+
- Service lifecycle management
|
|
299
|
+
|
|
300
|
+
See [tests/README.md](tests/README.md) for detailed test documentation.
|
|
301
|
+
|
|
302
|
+
## How It Works
|
|
303
|
+
npm run orchestrator:dev
|
|
304
|
+
|
|
305
|
+
# Plugin with watch
|
|
306
|
+
cd packages/serverless-plugin
|
|
307
|
+
npm run dev
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## How It Works
|
|
311
|
+
|
|
312
|
+
### Part 1: Initialization & Service Registration
|
|
313
|
+
|
|
314
|
+
```mermaid
|
|
315
|
+
sequenceDiagram
|
|
316
|
+
participant Dev as Developer
|
|
317
|
+
participant CLI as LSS CLI
|
|
318
|
+
participant Orch as Orchestrator
|
|
319
|
+
participant LS as LocalStack
|
|
320
|
+
participant Plugin as Serverless Plugin
|
|
321
|
+
participant SLS as Serverless Offline
|
|
322
|
+
|
|
323
|
+
Note over Dev,SLS: 1. Start LSS Environment
|
|
324
|
+
Dev->>CLI: npx lss start
|
|
325
|
+
CLI->>Orch: Start orchestrator (port 3100)
|
|
326
|
+
Orch->>LS: Start LocalStack container (port 4566)
|
|
327
|
+
LS-->>Orch: Ready
|
|
328
|
+
Orch-->>CLI: ✅ Running (PID saved)
|
|
329
|
+
CLI-->>Dev: Dashboard: http://localhost:3100
|
|
330
|
+
|
|
331
|
+
Note over Dev,SLS: 2. Register Microservice
|
|
332
|
+
Dev->>Plugin: sls package
|
|
333
|
+
Plugin->>Plugin: Read CloudFormation template
|
|
334
|
+
Plugin->>Orch: POST /api/services/register
|
|
335
|
+
Note right of Plugin: Sends: service name,<br/>CFN template,<br/>invoke port
|
|
336
|
+
|
|
337
|
+
Orch->>Orch: Parse CloudFormation
|
|
338
|
+
Note right of Orch: Extract:<br/>- DynamoDB tables<br/>- SQS queues<br/>- SNS topics<br/>- Event Source Mappings
|
|
339
|
+
|
|
340
|
+
Note over Orch,LS: 3. Provision Resources
|
|
341
|
+
Orch->>LS: Create DynamoDB tables
|
|
342
|
+
LS-->>Orch: Tables created
|
|
343
|
+
Orch->>LS: Create SQS queues (+ DLQs)
|
|
344
|
+
LS-->>Orch: Queues created
|
|
345
|
+
Orch->>LS: Create SNS topics
|
|
346
|
+
LS-->>Orch: Topics created
|
|
347
|
+
|
|
348
|
+
Note over Orch,LS: 4. Create Lambda Proxies (on-demand)
|
|
349
|
+
loop For each Event Source Mapping
|
|
350
|
+
Orch->>Orch: Generate proxy Lambda code
|
|
351
|
+
Note right of Orch: Proxy points to<br/>Serverless Offline
|
|
352
|
+
Orch->>LS: Create Lambda proxy function
|
|
353
|
+
LS-->>Orch: Proxy created
|
|
354
|
+
Orch->>LS: Create Event Source Mapping
|
|
355
|
+
Note right of Orch: SQS/DynamoDB/SNS → Lambda
|
|
356
|
+
LS-->>Orch: Mapping active
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
Orch-->>Plugin: ✅ Service registered
|
|
360
|
+
Plugin-->>Dev: ✅ Provisioned resources
|
|
361
|
+
|
|
362
|
+
Note over Dev,SLS: 5. Start Application
|
|
363
|
+
Dev->>SLS: serverless offline start
|
|
364
|
+
Note right of SLS: Starts on port 3020<br/>Lambda invoke: 13020
|
|
365
|
+
SLS-->>Dev: ✅ Handlers ready
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Part 2: Event Processing Flow
|
|
369
|
+
|
|
370
|
+
```mermaid
|
|
371
|
+
sequenceDiagram
|
|
372
|
+
participant App as Application
|
|
373
|
+
participant SQS as SQS Queue<br/>(LocalStack)
|
|
374
|
+
participant LS as LocalStack
|
|
375
|
+
participant Proxy as Lambda Proxy<br/>(LocalStack)
|
|
376
|
+
participant SLS as Serverless Offline
|
|
377
|
+
participant Handler as Lambda Handler
|
|
378
|
+
|
|
379
|
+
Note over App,Handler: Message Processing Flow
|
|
380
|
+
|
|
381
|
+
App->>SQS: Send message to queue
|
|
382
|
+
Note right of App: AWS SDK configured<br/>to LocalStack endpoint
|
|
383
|
+
SQS-->>App: Message accepted
|
|
384
|
+
|
|
385
|
+
Note over SQS,LS: Event Source Mapping Active
|
|
386
|
+
LS->>SQS: Poll for messages (BatchSize: 1-10)
|
|
387
|
+
SQS-->>LS: Return message(s)
|
|
388
|
+
|
|
389
|
+
LS->>Proxy: Invoke Lambda proxy
|
|
390
|
+
Note right of LS: Event with Records[]:<br/>- SQS message body<br/>- Attributes<br/>- Message ID
|
|
391
|
+
|
|
392
|
+
Note over Proxy,SLS: Proxy Forwards to Serverless Offline
|
|
393
|
+
Proxy->>Proxy: Transform event if needed
|
|
394
|
+
Note right of Proxy: Ensure Records[] format
|
|
395
|
+
|
|
396
|
+
Proxy->>SLS: HTTP POST /2015-03-31/functions/<br/>{functionName}/invocations
|
|
397
|
+
Note right of Proxy: Headers:<br/>- Content-Type: application/json<br/>- X-Amz-Invocation-Type
|
|
398
|
+
|
|
399
|
+
SLS->>Handler: Execute handler(event, context)
|
|
400
|
+
Note right of Handler: Real business logic<br/>runs here
|
|
401
|
+
|
|
402
|
+
alt Handler Success
|
|
403
|
+
Handler-->>SLS: Return response
|
|
404
|
+
SLS-->>Proxy: 200 OK + response body
|
|
405
|
+
Proxy-->>LS: Success
|
|
406
|
+
LS->>SQS: Delete message from queue
|
|
407
|
+
else Handler Error
|
|
408
|
+
Handler-->>SLS: Throw error
|
|
409
|
+
SLS-->>Proxy: 500 Error
|
|
410
|
+
Proxy-->>LS: Error
|
|
411
|
+
LS->>SQS: Return to queue or send to DLQ
|
|
412
|
+
Note right of SQS: Based on retry policy
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
Note over App,Handler: Processing Complete
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### Detailed Explanation
|
|
419
|
+
|
|
420
|
+
1. **Service Registration**:
|
|
421
|
+
- Developer runs `sls package` in their microservice
|
|
422
|
+
- Plugin reads `.serverless/cloudformation-template-update-stack.json`
|
|
423
|
+
- Plugin POSTs to orchestrator `/api/services/register` with service metadata
|
|
424
|
+
|
|
425
|
+
2. **Resource Provisioning**:
|
|
426
|
+
- Orchestrator parses CloudFormation template
|
|
427
|
+
- Extracts DynamoDB tables, SQS queues, SNS topics
|
|
428
|
+
- Creates resources in LocalStack via AWS SDK
|
|
429
|
+
- **Only creates Lambda proxies when Event Source Mappings exist**
|
|
430
|
+
- Generates proxy code that forwards to serverless-offline invoke endpoint
|
|
431
|
+
- Creates event source mappings (SQS/DynamoDB/SNS → Lambda)
|
|
432
|
+
|
|
433
|
+
3. **Event Flow**:
|
|
434
|
+
- Message arrives in SQS queue
|
|
435
|
+
- LocalStack polls queue via event source mapping
|
|
436
|
+
- Lambda proxy is triggered automatically
|
|
437
|
+
- Proxy transforms event and makes HTTP POST to serverless-offline
|
|
438
|
+
- Real handler executes in serverless-offline process
|
|
439
|
+
- Response returned through proxy chain
|
|
440
|
+
- Message deleted from queue on success, or sent to DLQ on failure
|
|
441
|
+
|
|
442
|
+
## CLI Implementation Details
|
|
443
|
+
|
|
444
|
+
The `npx lss` CLI is implemented in `/bin/cli.js` and provides:
|
|
445
|
+
|
|
446
|
+
- **Background Process Management**: Uses `spawn` with `detached: true` to run orchestrator independently
|
|
447
|
+
- **PID File**: Stores process ID in `/tmp/lss-orchestrator.pid`
|
|
448
|
+
- **Log File**: Redirects stdout/stderr to `/tmp/lss-orchestrator.log`
|
|
449
|
+
- **Process Monitoring**: Checks if process is alive before starting/stopping
|
|
450
|
+
- **Clean Shutdown**: Sends SIGTERM for graceful termination
|
|
451
|
+
|
|
452
|
+
### Files
|
|
453
|
+
|
|
454
|
+
- **PID File**: `/tmp/lss-orchestrator.pid`
|
|
455
|
+
- **Log File**: `/tmp/lss-orchestrator.log`
|
|
456
|
+
|
|
457
|
+
## Troubleshooting
|
|
458
|
+
|
|
459
|
+
### Check Logs
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
npx lss logs
|
|
463
|
+
|
|
464
|
+
# Or directly
|
|
465
|
+
tail -f /tmp/lss-orchestrator.log
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
### Orchestrator Won't Start
|
|
469
|
+
|
|
470
|
+
```bash
|
|
471
|
+
# Check if already running
|
|
472
|
+
npx lss status
|
|
473
|
+
|
|
474
|
+
# Check if build is complete
|
|
475
|
+
ls -la /workspaces/local-serverless-stack/dist/server/
|
|
476
|
+
ls -la /workspaces/local-serverless-stack/dist/ui/
|
|
477
|
+
|
|
478
|
+
# Rebuild if needed
|
|
479
|
+
npm run build
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Port Already in Use
|
|
483
|
+
|
|
484
|
+
The orchestrator uses port 3100 by default. If this port is in use:
|
|
485
|
+
|
|
486
|
+
```bash
|
|
487
|
+
# Find process using port 3100
|
|
488
|
+
lsof -i :3100
|
|
489
|
+
|
|
490
|
+
# Kill if needed
|
|
491
|
+
kill -9 <PID>
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
## Optional Features
|
|
495
|
+
|
|
496
|
+
### DynamoDB Proxy (Port 8000)
|
|
497
|
+
|
|
498
|
+
The orchestrator includes an optional reverse proxy on port 8000 that forwards to LocalStack (4566).
|
|
499
|
+
|
|
500
|
+
Enable with:
|
|
501
|
+
```bash
|
|
502
|
+
ENABLE_DYNAMO_PROXY=true npm run server:dev
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
Located in: `src/server/dev/dynamo-proxy.ts`
|
|
506
|
+
|
|
507
|
+
## Project Status
|
|
508
|
+
|
|
509
|
+
⚠️ **Version 0.1.0 - Internal Development**
|
|
510
|
+
|
|
511
|
+
This project is currently in active development and is being used internally. It is not yet published to npm.
|
|
512
|
+
|
|
513
|
+
### Completed Features
|
|
514
|
+
|
|
515
|
+
- ✅ CLI with start/stop/status/logs commands
|
|
516
|
+
- ✅ Background process management
|
|
517
|
+
- ✅ Serverless Framework plugin
|
|
518
|
+
- ✅ Auto-provisioning of AWS resources
|
|
519
|
+
- ✅ Event source mapping (SQS → Lambda)
|
|
520
|
+
- ✅ Web dashboard (Vue 3)
|
|
521
|
+
- ✅ npm link support for local development
|
|
522
|
+
|
|
523
|
+
## Use Case Example
|
|
524
|
+
|
|
525
|
+
LSS can be used in monorepo setups to manage 15+ microservices with a single LocalStack instance. This eliminates the complexity of running multiple LocalStack containers and provides a unified development experience.
|
|
526
|
+
|
|
527
|
+
Integration approach:
|
|
528
|
+
- Place LSS in a dedicated directory (e.g., `/workspaces/local-serverless-stack`)
|
|
529
|
+
- Use `npm link` for local development and seamless updates
|
|
530
|
+
- Install the plugin in each microservice that needs AWS resource orchestration
|
|
531
|
+
- Orchestrator managed via `npx lss start/stop` commands
|
|
532
|
+
|
|
533
|
+
## Contributing
|
|
534
|
+
|
|
535
|
+
Contributions welcome! This is an open-source project designed to simplify local serverless development.
|
|
536
|
+
|
|
537
|
+
## License
|
|
538
|
+
|
|
539
|
+
MIT
|
|
540
|
+
|
|
541
|
+
## Publishing to npm
|
|
542
|
+
|
|
543
|
+
⚠️ **For maintainers only**
|
|
544
|
+
|
|
545
|
+
### Automatic Publishing (Recommended)
|
|
546
|
+
|
|
547
|
+
The project uses GitHub Actions for automatic publishing to NPM when you update the version:
|
|
548
|
+
|
|
549
|
+
**1. Update version in package.json**:
|
|
550
|
+
```bash
|
|
551
|
+
# For the root package (CLI + orchestrator)
|
|
552
|
+
npm version patch # 0.0.1 -> 0.0.2
|
|
553
|
+
npm version minor # 0.0.1 -> 0.1.0
|
|
554
|
+
npm version major # 0.0.1 -> 1.0.0
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
**2. Push to main branch**:
|
|
558
|
+
```bash
|
|
559
|
+
git add package.json CHANGELOG.md
|
|
560
|
+
git commit -m "chore: bump version to 0.0.2"
|
|
561
|
+
git push origin main
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
**3. GitHub Actions will automatically**:
|
|
565
|
+
- ✅ Detect version change
|
|
566
|
+
- ✅ Run full test suite
|
|
567
|
+
- ✅ Build the project
|
|
568
|
+
- ✅ Publish to NPM
|
|
569
|
+
- ✅ Create a git tag (e.g., `v0.0.2`)
|
|
570
|
+
|
|
571
|
+
### Plugin Package
|
|
572
|
+
|
|
573
|
+
To publish the serverless plugin separately:
|
|
574
|
+
|
|
575
|
+
```bash
|
|
576
|
+
cd packages/serverless-plugin
|
|
577
|
+
npm version patch
|
|
578
|
+
cd ../..
|
|
579
|
+
git add packages/serverless-plugin/package.json
|
|
580
|
+
git commit -m "chore(plugin): bump version to 0.0.2"
|
|
581
|
+
git push origin main
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
### Required Setup (One-time)
|
|
585
|
+
|
|
586
|
+
Before automatic publishing works:
|
|
587
|
+
|
|
588
|
+
1. **NPM Access Token**:
|
|
589
|
+
- Go to npmjs.com → Access Tokens → Generate New Token
|
|
590
|
+
- Select "Automation" type
|
|
591
|
+
- Copy the token
|
|
592
|
+
|
|
593
|
+
2. **GitHub Secret**:
|
|
594
|
+
- Go to your repo → Settings → Secrets and variables → Actions
|
|
595
|
+
- Add new repository secret: `NPM_TOKEN`
|
|
596
|
+
- Paste your NPM token
|
|
597
|
+
|
|
598
|
+
### Pre-publish Checklist
|
|
599
|
+
|
|
600
|
+
1. ✅ All tests passing
|
|
601
|
+
2. ✅ Build successful (`npm run build`)
|
|
602
|
+
3. ✅ Version updated in `package.json`
|
|
603
|
+
4. ✅ CHANGELOG.md updated
|
|
604
|
+
5. ✅ README.md updated
|
|
605
|
+
6. ✅ No breaking changes (or properly documented)
|
|
606
|
+
|
|
607
|
+
### Manual Publishing (Emergency Only)
|
|
608
|
+
|
|
609
|
+
If GitHub Actions fails, you can publish manually:
|
|
610
|
+
|
|
611
|
+
```bash
|
|
612
|
+
# 1. Ensure clean working directory
|
|
613
|
+
git status
|
|
614
|
+
|
|
615
|
+
# 2. Build all packages
|
|
616
|
+
npm run build
|
|
617
|
+
|
|
618
|
+
# 3. Test the package contents
|
|
619
|
+
npm pack
|
|
620
|
+
tar -tzf local-serverless-stack-*.tgz
|
|
621
|
+
|
|
622
|
+
# 4. Publish to npm (dry-run first)
|
|
623
|
+
npm publish --dry-run
|
|
624
|
+
|
|
625
|
+
# 5. Publish for real
|
|
626
|
+
npm publish --access public
|
|
627
|
+
|
|
628
|
+
# 6. Create git tag
|
|
629
|
+
git tag v0.0.1
|
|
630
|
+
git push origin v0.0.1
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
### What Gets Published
|
|
634
|
+
|
|
635
|
+
The `files` field in package.json controls what's published:
|
|
636
|
+
|
|
637
|
+
- `bin/` - CLI scripts
|
|
638
|
+
- `dist/` - Compiled server + UI
|
|
639
|
+
- `packages/serverless-plugin/dist/` - Compiled plugin
|
|
640
|
+
- `README.md`, `LICENSE`, `CHANGELOG.md`
|
|
641
|
+
|
|
642
|
+
Source files and development dependencies are **not** included.
|
|
643
|
+
|
|
644
|
+
### Post-publish
|
|
645
|
+
|
|
646
|
+
After publishing, users can install with:
|
|
647
|
+
|
|
648
|
+
```bash
|
|
649
|
+
npm install local-serverless-stack
|
|
650
|
+
npx lss start
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
No build step required for end users!
|