packwise-skills 1.0.0 → 1.2.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.
- package/.cursorrules +23 -23
- package/CLAUDE.md +25 -25
- package/LICENSE +21 -0
- package/README.md +404 -295
- package/audit.md +224 -224
- package/bin/packwise.js +322 -155
- package/install.sh +123 -0
- package/package.json +32 -31
- package/skill.md +944 -719
- package/sub-skills/ai/local-llm.md +183 -183
- package/sub-skills/ai/python-ml.md +164 -164
- package/sub-skills/backend/go-server.md +184 -184
- package/sub-skills/backend/java-spring.md +241 -241
- package/sub-skills/backend/node-server.md +164 -164
- package/sub-skills/backend/php-laravel.md +175 -175
- package/sub-skills/backend/python-server.md +164 -164
- package/sub-skills/backend/rust-backend.md +118 -118
- package/sub-skills/cli/python-cli.md +236 -236
- package/sub-skills/cli/sdk-library.md +497 -497
- package/sub-skills/cloud/ci-cd-pipelines.md +350 -350
- package/sub-skills/cloud/docker.md +191 -191
- package/sub-skills/cloud/kubernetes.md +277 -277
- package/sub-skills/cloud/payment-integration.md +307 -307
- package/sub-skills/cross-platform/multiplatform.md +252 -252
- package/sub-skills/desktop/electron.md +783 -783
- package/sub-skills/desktop/game-dev.md +443 -443
- package/sub-skills/desktop/native-app.md +123 -123
- package/sub-skills/desktop/scenarios.md +443 -443
- package/sub-skills/desktop/smart-platforms.md +324 -324
- package/sub-skills/desktop/tauri.md +428 -428
- package/sub-skills/desktop/vr-ar.md +252 -252
- package/sub-skills/desktop/web-to-desktop.md +153 -153
- package/sub-skills/embedded/car-infotainment.md +129 -129
- package/sub-skills/embedded/esp32.md +184 -184
- package/sub-skills/embedded/ros.md +150 -150
- package/sub-skills/embedded/stm32.md +160 -160
- package/sub-skills/mobile/android.md +322 -322
- package/sub-skills/mobile/capacitor.md +232 -232
- package/sub-skills/mobile/flutter-mobile.md +138 -138
- package/sub-skills/mobile/harmonyos.md +150 -150
- package/sub-skills/mobile/ios.md +245 -245
- package/sub-skills/mobile/react-native.md +443 -443
- package/sub-skills/mobile/wearables.md +230 -230
- package/sub-skills/plugins/browser-extension.md +308 -308
- package/sub-skills/plugins/jetbrains-plugin.md +226 -226
- package/sub-skills/plugins/vscode-extension.md +204 -204
- package/sub-skills/security/security-tools.md +174 -174
- package/sub-skills/web/monorepo.md +274 -274
- package/sub-skills/web/pwa.md +220 -220
- package/sub-skills/web/serverless-edge.md +295 -295
- package/sub-skills/web/spa.md +266 -266
- package/sub-skills/web/ssr.md +228 -228
- package/sub-skills/web/wasm.md +243 -243
|
@@ -1,295 +1,295 @@
|
|
|
1
|
-
# Serverless & Edge Build Sub-Skill
|
|
2
|
-
|
|
3
|
-
Build and package applications for serverless platforms and edge runtimes.
|
|
4
|
-
|
|
5
|
-
**Current versions**: AWS Lambda / Cloudflare Workers / Vercel Functions / Deno Deploy (2025-2026)
|
|
6
|
-
|
|
7
|
-
## When to Use
|
|
8
|
-
|
|
9
|
-
- Pay-per-request pricing model
|
|
10
|
-
- Auto-scaling without infrastructure management
|
|
11
|
-
- API backends with variable traffic
|
|
12
|
-
- Edge computing (low latency globally)
|
|
13
|
-
- Cron jobs / scheduled tasks
|
|
14
|
-
- Webhook handlers
|
|
15
|
-
|
|
16
|
-
## Platform Comparison
|
|
17
|
-
|
|
18
|
-
| Platform | Language Support | Cold Start | Max Duration | Best For |
|
|
19
|
-
|----------|-----------------|-----------|-------------|---------|
|
|
20
|
-
| AWS Lambda | Node/Python/Go/Rust/Java/.NET | 100–500ms | 15 min | Enterprise, complex workflows |
|
|
21
|
-
| Cloudflare Workers | JS/TS/WASM | < 1ms | 30s (CPU) / unlimited (I/O) | Edge compute, APIs |
|
|
22
|
-
| Vercel Functions | Node/Python/Go/Ruby | 100–300ms | 60s (free) / 900s (pro) | Next.js apps, frontend APIs |
|
|
23
|
-
| Deno Deploy | JS/TS | < 10ms | 50ms–60s | Lightweight APIs, edge |
|
|
24
|
-
| Netlify Functions | Node/Go | 100–500ms | 10s (free) / 26s (pro) | JAMstack apps |
|
|
25
|
-
| Azure Functions | Node/Python/C#/Java/PowerShell | 100–500ms | 10 min (consumption) | .NET ecosystem |
|
|
26
|
-
| Google Cloud Functions | Node/Python/Go/Java/.NET/Ruby | 100–500ms | 60 min (gen2) | GCP ecosystem |
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## AWS Lambda
|
|
31
|
-
|
|
32
|
-
### Node.js Function
|
|
33
|
-
|
|
34
|
-
```javascript
|
|
35
|
-
// handler.js (Lambda Function URL or API Gateway)
|
|
36
|
-
exports.handler = async (event) => {
|
|
37
|
-
const name = event.queryStringParameters?.name || 'World';
|
|
38
|
-
return {
|
|
39
|
-
statusCode: 200,
|
|
40
|
-
headers: { 'Content-Type': 'application/json' },
|
|
41
|
-
body: JSON.stringify({ message: `Hello, ${name}!` }),
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
# Package
|
|
48
|
-
zip -r function.zip handler.js node_modules/
|
|
49
|
-
|
|
50
|
-
# Deploy with AWS CLI
|
|
51
|
-
aws lambda create-function \
|
|
52
|
-
--function-name my-function \
|
|
53
|
-
--runtime nodejs22.x \
|
|
54
|
-
--handler handler.handler \
|
|
55
|
-
--zip-file fileb://function.zip \
|
|
56
|
-
--role arn:aws:iam::ACCOUNT:role/lambda-role
|
|
57
|
-
|
|
58
|
-
# Or with SAM (Serverless Application Model)
|
|
59
|
-
sam build && sam deploy --guided
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Python Function
|
|
63
|
-
|
|
64
|
-
```python
|
|
65
|
-
# lambda_function.py
|
|
66
|
-
import json
|
|
67
|
-
|
|
68
|
-
def handler(event, context):
|
|
69
|
-
name = event.get('queryStringParameters', {}).get('name', 'World')
|
|
70
|
-
return {
|
|
71
|
-
'statusCode': 200,
|
|
72
|
-
'headers': {'Content-Type': 'application/json'},
|
|
73
|
-
'body': json.dumps({'message': f'Hello, {name}!'})
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### Go Function
|
|
78
|
-
|
|
79
|
-
```go
|
|
80
|
-
package main
|
|
81
|
-
|
|
82
|
-
import (
|
|
83
|
-
"context"
|
|
84
|
-
"github.com/aws/aws-lambda-go/events"
|
|
85
|
-
"github.com/aws/aws-lambda-go/lambda"
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
|
|
89
|
-
name := request.QueryStringParameters["name"]
|
|
90
|
-
if name == "" { name = "World" }
|
|
91
|
-
return events.APIGatewayProxyResponse{
|
|
92
|
-
StatusCode: 200,
|
|
93
|
-
Headers: map[string]string{"Content-Type": "application/json"},
|
|
94
|
-
Body: fmt.Sprintf(`{"message":"Hello, %s!"}`, name),
|
|
95
|
-
}, nil
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
func main() { lambda.Start(handler) }
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
# Build and deploy
|
|
103
|
-
GOOS=linux GOARCH=amd64 go build -o bootstrap main.go
|
|
104
|
-
zip function.zip bootstrap
|
|
105
|
-
aws lambda create-function --function-name my-go-func --runtime provided.al2023 --handler bootstrap --zip-file fileb://function.zip
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### Rust Function (Custom Runtime)
|
|
109
|
-
|
|
110
|
-
```toml
|
|
111
|
-
# Cargo.toml
|
|
112
|
-
[dependencies]
|
|
113
|
-
lambda_runtime = "0.13"
|
|
114
|
-
tokio = { version = "1", features = ["macros"] }
|
|
115
|
-
serde = { version = "1", features = ["derive"] }
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
```rust
|
|
119
|
-
use lambda_runtime::{service_fn, LambdaEvent, Error};
|
|
120
|
-
use serde_json::{json, Value};
|
|
121
|
-
|
|
122
|
-
async fn handler(event: LambdaEvent<Value>) -> Result<Value, Error> {
|
|
123
|
-
let name = event.payload.get("name").and_then(|v| v.as_str()).unwrap_or("World");
|
|
124
|
-
Ok(json!({ "statusCode": 200, "body": format!("Hello, {}!", name) }))
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
#[tokio::main]
|
|
128
|
-
async fn main() -> Result<(), Error> {
|
|
129
|
-
lambda_runtime::run(service_fn(handler)).await
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
---
|
|
134
|
-
|
|
135
|
-
## Cloudflare Workers
|
|
136
|
-
|
|
137
|
-
```bash
|
|
138
|
-
# Create project
|
|
139
|
-
npm create cloudflare@latest my-worker
|
|
140
|
-
cd my-worker
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
```javascript
|
|
144
|
-
// src/index.js
|
|
145
|
-
export default {
|
|
146
|
-
async fetch(request, env, ctx) {
|
|
147
|
-
const url = new URL(request.url);
|
|
148
|
-
if (url.pathname === '/health') {
|
|
149
|
-
return new Response('OK', { status: 200 });
|
|
150
|
-
}
|
|
151
|
-
return new Response('Hello from the Edge!', { status: 200 });
|
|
152
|
-
},
|
|
153
|
-
// Scheduled handler (cron)
|
|
154
|
-
async scheduled(event, env, ctx) {
|
|
155
|
-
// Runs on cron schedule defined in wrangler.toml
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
```toml
|
|
161
|
-
# wrangler.toml
|
|
162
|
-
name = "my-worker"
|
|
163
|
-
main = "src/index.js"
|
|
164
|
-
compatibility_date = "2025-01-01"
|
|
165
|
-
|
|
166
|
-
[triggers]
|
|
167
|
-
crons = ["*/5 * * * *"] # Every 5 minutes
|
|
168
|
-
|
|
169
|
-
# KV Storage
|
|
170
|
-
[[kv_namespaces]]
|
|
171
|
-
binding = "CACHE"
|
|
172
|
-
id = "your-kv-namespace-id"
|
|
173
|
-
|
|
174
|
-
# D1 Database
|
|
175
|
-
[[d1_databases]]
|
|
176
|
-
binding = "DB"
|
|
177
|
-
database_name = "my-db"
|
|
178
|
-
database_id = "your-d1-database-id"
|
|
179
|
-
|
|
180
|
-
# R2 Storage (S3-compatible)
|
|
181
|
-
[[r2_buckets]]
|
|
182
|
-
binding = "STORAGE"
|
|
183
|
-
bucket_name = "my-bucket"
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
```bash
|
|
187
|
-
# Deploy
|
|
188
|
-
npx wrangler deploy
|
|
189
|
-
|
|
190
|
-
# Test locally
|
|
191
|
-
npx wrangler dev
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
---
|
|
195
|
-
|
|
196
|
-
## Vercel Functions
|
|
197
|
-
|
|
198
|
-
```javascript
|
|
199
|
-
// app/api/hello/route.js (Next.js App Router)
|
|
200
|
-
export async function GET(request) {
|
|
201
|
-
return Response.json({ message: 'Hello from Vercel!' });
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export async function POST(request) {
|
|
205
|
-
const body = await request.json();
|
|
206
|
-
return Response.json({ received: body });
|
|
207
|
-
}
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
```bash
|
|
211
|
-
# Deploy
|
|
212
|
-
vercel deploy
|
|
213
|
-
|
|
214
|
-
# Or: git push to connected repository (auto-deploy)
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## Deno Deploy
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
// main.ts
|
|
223
|
-
Deno.serve((req: Request) => {
|
|
224
|
-
const url = new URL(req.url);
|
|
225
|
-
if (url.pathname === "/health") {
|
|
226
|
-
return new Response("OK");
|
|
227
|
-
}
|
|
228
|
-
return new Response("Hello from Deno Deploy!");
|
|
229
|
-
});
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
```bash
|
|
233
|
-
# Deploy
|
|
234
|
-
deployctl deploy --project=my-project main.ts
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
---
|
|
238
|
-
|
|
239
|
-
## Serverless Framework (Multi-Cloud)
|
|
240
|
-
|
|
241
|
-
```yaml
|
|
242
|
-
# serverless.yml
|
|
243
|
-
service: my-service
|
|
244
|
-
frameworkVersion: '3'
|
|
245
|
-
|
|
246
|
-
provider:
|
|
247
|
-
name: aws
|
|
248
|
-
runtime: nodejs22.x
|
|
249
|
-
region: us-east-1
|
|
250
|
-
|
|
251
|
-
functions:
|
|
252
|
-
api:
|
|
253
|
-
handler: handler.handler
|
|
254
|
-
events:
|
|
255
|
-
- httpApi:
|
|
256
|
-
path: /{proxy+}
|
|
257
|
-
method: '*'
|
|
258
|
-
- schedule:
|
|
259
|
-
rate: rate(1 hour)
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
```bash
|
|
263
|
-
npm install -g serverless
|
|
264
|
-
serverless deploy
|
|
265
|
-
serverless info # Get endpoint URLs
|
|
266
|
-
serverless logs -f api # View logs
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
---
|
|
270
|
-
|
|
271
|
-
## Selection Guide
|
|
272
|
-
|
|
273
|
-
| Scenario | Recommended Platform | Why |
|
|
274
|
-
|----------|---------------------|-----|
|
|
275
|
-
| Next.js app | Vercel | First-class Next.js support |
|
|
276
|
-
| Global API with low latency | Cloudflare Workers | Edge-first, < 1ms cold start |
|
|
277
|
-
| Enterprise backend | AWS Lambda + API Gateway | Full AWS ecosystem |
|
|
278
|
-
| .NET backend | Azure Functions | Native .NET support |
|
|
279
|
-
| Cron jobs / scheduled tasks | Any (all support cron) | Pick based on existing infra |
|
|
280
|
-
| AI inference at edge | Cloudflare Workers AI | GPU at the edge |
|
|
281
|
-
| Simple webhook handler | Vercel/Netlify Functions | Easiest setup |
|
|
282
|
-
| High-memory workloads | AWS Lambda (10GB) | Highest memory allocation |
|
|
283
|
-
|
|
284
|
-
## Common Pitfalls
|
|
285
|
-
|
|
286
|
-
| Issue | Fix |
|
|
287
|
-
|-------|-----|
|
|
288
|
-
| Cold start too slow | Use provisioned concurrency (AWS); keep functions small |
|
|
289
|
-
| Function timeout | Break into smaller functions; use async queues (SQS/Queues) |
|
|
290
|
-
| Package too large | Use tree-shaking; exclude dev deps; use Lambda layers |
|
|
291
|
-
| Environment variables not available | Set in platform dashboard; use secrets manager |
|
|
292
|
-
| Database connection exhaustion | Use connection pooling (RDS Proxy, Neon, PlanetScale) |
|
|
293
|
-
| CORS errors | Add CORS headers in function response |
|
|
294
|
-
| Webhook replay attacks | Verify webhook signatures (Stripe, GitHub) |
|
|
295
|
-
| Edge runtime limitations | No filesystem access; limited Node.js APIs; no native modules |
|
|
1
|
+
# Serverless & Edge Build Sub-Skill
|
|
2
|
+
|
|
3
|
+
Build and package applications for serverless platforms and edge runtimes.
|
|
4
|
+
|
|
5
|
+
**Current versions**: AWS Lambda / Cloudflare Workers / Vercel Functions / Deno Deploy (2025-2026)
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
- Pay-per-request pricing model
|
|
10
|
+
- Auto-scaling without infrastructure management
|
|
11
|
+
- API backends with variable traffic
|
|
12
|
+
- Edge computing (low latency globally)
|
|
13
|
+
- Cron jobs / scheduled tasks
|
|
14
|
+
- Webhook handlers
|
|
15
|
+
|
|
16
|
+
## Platform Comparison
|
|
17
|
+
|
|
18
|
+
| Platform | Language Support | Cold Start | Max Duration | Best For |
|
|
19
|
+
|----------|-----------------|-----------|-------------|---------|
|
|
20
|
+
| AWS Lambda | Node/Python/Go/Rust/Java/.NET | 100–500ms | 15 min | Enterprise, complex workflows |
|
|
21
|
+
| Cloudflare Workers | JS/TS/WASM | < 1ms | 30s (CPU) / unlimited (I/O) | Edge compute, APIs |
|
|
22
|
+
| Vercel Functions | Node/Python/Go/Ruby | 100–300ms | 60s (free) / 900s (pro) | Next.js apps, frontend APIs |
|
|
23
|
+
| Deno Deploy | JS/TS | < 10ms | 50ms–60s | Lightweight APIs, edge |
|
|
24
|
+
| Netlify Functions | Node/Go | 100–500ms | 10s (free) / 26s (pro) | JAMstack apps |
|
|
25
|
+
| Azure Functions | Node/Python/C#/Java/PowerShell | 100–500ms | 10 min (consumption) | .NET ecosystem |
|
|
26
|
+
| Google Cloud Functions | Node/Python/Go/Java/.NET/Ruby | 100–500ms | 60 min (gen2) | GCP ecosystem |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## AWS Lambda
|
|
31
|
+
|
|
32
|
+
### Node.js Function
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
// handler.js (Lambda Function URL or API Gateway)
|
|
36
|
+
exports.handler = async (event) => {
|
|
37
|
+
const name = event.queryStringParameters?.name || 'World';
|
|
38
|
+
return {
|
|
39
|
+
statusCode: 200,
|
|
40
|
+
headers: { 'Content-Type': 'application/json' },
|
|
41
|
+
body: JSON.stringify({ message: `Hello, ${name}!` }),
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Package
|
|
48
|
+
zip -r function.zip handler.js node_modules/
|
|
49
|
+
|
|
50
|
+
# Deploy with AWS CLI
|
|
51
|
+
aws lambda create-function \
|
|
52
|
+
--function-name my-function \
|
|
53
|
+
--runtime nodejs22.x \
|
|
54
|
+
--handler handler.handler \
|
|
55
|
+
--zip-file fileb://function.zip \
|
|
56
|
+
--role arn:aws:iam::ACCOUNT:role/lambda-role
|
|
57
|
+
|
|
58
|
+
# Or with SAM (Serverless Application Model)
|
|
59
|
+
sam build && sam deploy --guided
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Python Function
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
# lambda_function.py
|
|
66
|
+
import json
|
|
67
|
+
|
|
68
|
+
def handler(event, context):
|
|
69
|
+
name = event.get('queryStringParameters', {}).get('name', 'World')
|
|
70
|
+
return {
|
|
71
|
+
'statusCode': 200,
|
|
72
|
+
'headers': {'Content-Type': 'application/json'},
|
|
73
|
+
'body': json.dumps({'message': f'Hello, {name}!'})
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Go Function
|
|
78
|
+
|
|
79
|
+
```go
|
|
80
|
+
package main
|
|
81
|
+
|
|
82
|
+
import (
|
|
83
|
+
"context"
|
|
84
|
+
"github.com/aws/aws-lambda-go/events"
|
|
85
|
+
"github.com/aws/aws-lambda-go/lambda"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
|
|
89
|
+
name := request.QueryStringParameters["name"]
|
|
90
|
+
if name == "" { name = "World" }
|
|
91
|
+
return events.APIGatewayProxyResponse{
|
|
92
|
+
StatusCode: 200,
|
|
93
|
+
Headers: map[string]string{"Content-Type": "application/json"},
|
|
94
|
+
Body: fmt.Sprintf(`{"message":"Hello, %s!"}`, name),
|
|
95
|
+
}, nil
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
func main() { lambda.Start(handler) }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Build and deploy
|
|
103
|
+
GOOS=linux GOARCH=amd64 go build -o bootstrap main.go
|
|
104
|
+
zip function.zip bootstrap
|
|
105
|
+
aws lambda create-function --function-name my-go-func --runtime provided.al2023 --handler bootstrap --zip-file fileb://function.zip
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Rust Function (Custom Runtime)
|
|
109
|
+
|
|
110
|
+
```toml
|
|
111
|
+
# Cargo.toml
|
|
112
|
+
[dependencies]
|
|
113
|
+
lambda_runtime = "0.13"
|
|
114
|
+
tokio = { version = "1", features = ["macros"] }
|
|
115
|
+
serde = { version = "1", features = ["derive"] }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```rust
|
|
119
|
+
use lambda_runtime::{service_fn, LambdaEvent, Error};
|
|
120
|
+
use serde_json::{json, Value};
|
|
121
|
+
|
|
122
|
+
async fn handler(event: LambdaEvent<Value>) -> Result<Value, Error> {
|
|
123
|
+
let name = event.payload.get("name").and_then(|v| v.as_str()).unwrap_or("World");
|
|
124
|
+
Ok(json!({ "statusCode": 200, "body": format!("Hello, {}!", name) }))
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#[tokio::main]
|
|
128
|
+
async fn main() -> Result<(), Error> {
|
|
129
|
+
lambda_runtime::run(service_fn(handler)).await
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Cloudflare Workers
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Create project
|
|
139
|
+
npm create cloudflare@latest my-worker
|
|
140
|
+
cd my-worker
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
```javascript
|
|
144
|
+
// src/index.js
|
|
145
|
+
export default {
|
|
146
|
+
async fetch(request, env, ctx) {
|
|
147
|
+
const url = new URL(request.url);
|
|
148
|
+
if (url.pathname === '/health') {
|
|
149
|
+
return new Response('OK', { status: 200 });
|
|
150
|
+
}
|
|
151
|
+
return new Response('Hello from the Edge!', { status: 200 });
|
|
152
|
+
},
|
|
153
|
+
// Scheduled handler (cron)
|
|
154
|
+
async scheduled(event, env, ctx) {
|
|
155
|
+
// Runs on cron schedule defined in wrangler.toml
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
```toml
|
|
161
|
+
# wrangler.toml
|
|
162
|
+
name = "my-worker"
|
|
163
|
+
main = "src/index.js"
|
|
164
|
+
compatibility_date = "2025-01-01"
|
|
165
|
+
|
|
166
|
+
[triggers]
|
|
167
|
+
crons = ["*/5 * * * *"] # Every 5 minutes
|
|
168
|
+
|
|
169
|
+
# KV Storage
|
|
170
|
+
[[kv_namespaces]]
|
|
171
|
+
binding = "CACHE"
|
|
172
|
+
id = "your-kv-namespace-id"
|
|
173
|
+
|
|
174
|
+
# D1 Database
|
|
175
|
+
[[d1_databases]]
|
|
176
|
+
binding = "DB"
|
|
177
|
+
database_name = "my-db"
|
|
178
|
+
database_id = "your-d1-database-id"
|
|
179
|
+
|
|
180
|
+
# R2 Storage (S3-compatible)
|
|
181
|
+
[[r2_buckets]]
|
|
182
|
+
binding = "STORAGE"
|
|
183
|
+
bucket_name = "my-bucket"
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# Deploy
|
|
188
|
+
npx wrangler deploy
|
|
189
|
+
|
|
190
|
+
# Test locally
|
|
191
|
+
npx wrangler dev
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Vercel Functions
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
// app/api/hello/route.js (Next.js App Router)
|
|
200
|
+
export async function GET(request) {
|
|
201
|
+
return Response.json({ message: 'Hello from Vercel!' });
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export async function POST(request) {
|
|
205
|
+
const body = await request.json();
|
|
206
|
+
return Response.json({ received: body });
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
# Deploy
|
|
212
|
+
vercel deploy
|
|
213
|
+
|
|
214
|
+
# Or: git push to connected repository (auto-deploy)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Deno Deploy
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
// main.ts
|
|
223
|
+
Deno.serve((req: Request) => {
|
|
224
|
+
const url = new URL(req.url);
|
|
225
|
+
if (url.pathname === "/health") {
|
|
226
|
+
return new Response("OK");
|
|
227
|
+
}
|
|
228
|
+
return new Response("Hello from Deno Deploy!");
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
# Deploy
|
|
234
|
+
deployctl deploy --project=my-project main.ts
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Serverless Framework (Multi-Cloud)
|
|
240
|
+
|
|
241
|
+
```yaml
|
|
242
|
+
# serverless.yml
|
|
243
|
+
service: my-service
|
|
244
|
+
frameworkVersion: '3'
|
|
245
|
+
|
|
246
|
+
provider:
|
|
247
|
+
name: aws
|
|
248
|
+
runtime: nodejs22.x
|
|
249
|
+
region: us-east-1
|
|
250
|
+
|
|
251
|
+
functions:
|
|
252
|
+
api:
|
|
253
|
+
handler: handler.handler
|
|
254
|
+
events:
|
|
255
|
+
- httpApi:
|
|
256
|
+
path: /{proxy+}
|
|
257
|
+
method: '*'
|
|
258
|
+
- schedule:
|
|
259
|
+
rate: rate(1 hour)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
npm install -g serverless
|
|
264
|
+
serverless deploy
|
|
265
|
+
serverless info # Get endpoint URLs
|
|
266
|
+
serverless logs -f api # View logs
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Selection Guide
|
|
272
|
+
|
|
273
|
+
| Scenario | Recommended Platform | Why |
|
|
274
|
+
|----------|---------------------|-----|
|
|
275
|
+
| Next.js app | Vercel | First-class Next.js support |
|
|
276
|
+
| Global API with low latency | Cloudflare Workers | Edge-first, < 1ms cold start |
|
|
277
|
+
| Enterprise backend | AWS Lambda + API Gateway | Full AWS ecosystem |
|
|
278
|
+
| .NET backend | Azure Functions | Native .NET support |
|
|
279
|
+
| Cron jobs / scheduled tasks | Any (all support cron) | Pick based on existing infra |
|
|
280
|
+
| AI inference at edge | Cloudflare Workers AI | GPU at the edge |
|
|
281
|
+
| Simple webhook handler | Vercel/Netlify Functions | Easiest setup |
|
|
282
|
+
| High-memory workloads | AWS Lambda (10GB) | Highest memory allocation |
|
|
283
|
+
|
|
284
|
+
## Common Pitfalls
|
|
285
|
+
|
|
286
|
+
| Issue | Fix |
|
|
287
|
+
|-------|-----|
|
|
288
|
+
| Cold start too slow | Use provisioned concurrency (AWS); keep functions small |
|
|
289
|
+
| Function timeout | Break into smaller functions; use async queues (SQS/Queues) |
|
|
290
|
+
| Package too large | Use tree-shaking; exclude dev deps; use Lambda layers |
|
|
291
|
+
| Environment variables not available | Set in platform dashboard; use secrets manager |
|
|
292
|
+
| Database connection exhaustion | Use connection pooling (RDS Proxy, Neon, PlanetScale) |
|
|
293
|
+
| CORS errors | Add CORS headers in function response |
|
|
294
|
+
| Webhook replay attacks | Verify webhook signatures (Stripe, GitHub) |
|
|
295
|
+
| Edge runtime limitations | No filesystem access; limited Node.js APIs; no native modules |
|