@friggframework/devtools 2.0.0--canary.454.e2a280d.0 → 2.0.0--canary.458.c150d9a.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.
@@ -1,645 +0,0 @@
1
- # PostgreSQL (Aurora) Configuration Guide
2
-
3
- This guide covers Aurora PostgreSQL provisioning and configuration in Frigg Framework applications.
4
-
5
- ## Overview
6
-
7
- Frigg Framework supports automatic provisioning of Amazon Aurora Serverless v2 PostgreSQL databases for your integrations. Aurora databases are deployed in the same VPC as your Lambda functions with secure access via AWS Secrets Manager.
8
-
9
- ### Key Features
10
-
11
- - **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-1.0 ACU default)
12
- - **VPC Integration**: Deployed in same private subnets as Lambda functions
13
- - **Secrets Manager**: Automatic credential management and rotation
14
- - **Three Management Modes**: discover, create-new, use-existing
15
- - **Security**: Private subnet deployment with security group isolation
16
- - **High Availability**: Multi-AZ deployment with automatic failover
17
-
18
- ---
19
-
20
- ## Configuration Schema
21
-
22
- ### App Definition Structure
23
-
24
- ```javascript
25
- // backend/index.js
26
- const appDefinition = {
27
- name: 'my-frigg-app',
28
-
29
- // Enable VPC deployment (required for Aurora)
30
- vpc: {
31
- enable: true,
32
- },
33
-
34
- // Aurora PostgreSQL Configuration
35
- database: {
36
- postgres: {
37
- enable: true,
38
-
39
- // Management mode: 'discover' | 'create-new' | 'use-existing'
40
- management: 'discover',
41
-
42
- // Basic Configuration
43
- databaseName: 'frigg_db',
44
- masterUsername: 'frigg_admin',
45
-
46
- // Engine Configuration
47
- engine: 'aurora-postgresql',
48
- engineVersion: '15.3',
49
-
50
- // Scaling Configuration (Aurora Serverless v2)
51
- scaling: {
52
- minCapacity: 0.5, // ACUs (0.5 = ~1GB RAM, ~$43/month)
53
- maxCapacity: 1.0, // ACUs (1.0 = ~2GB RAM, ~$87/month)
54
- },
55
-
56
- // Backup Configuration
57
- backupRetentionDays: 7,
58
- preferredBackupWindow: '03:00-04:00',
59
-
60
- // Security & Advanced
61
- deletionProtection: true,
62
- enablePerformanceInsights: false,
63
-
64
- // For use-existing mode
65
- clusterIdentifier: 'my-existing-cluster',
66
- secretArn: 'arn:aws:secretsmanager:...',
67
- },
68
- },
69
- };
70
-
71
- module.exports = {
72
- Definition: appDefinition,
73
- };
74
- ```
75
-
76
- ---
77
-
78
- ## Management Modes
79
-
80
- ### 1. Discover Mode (Default)
81
-
82
- Automatically discovers existing Aurora clusters or creates new one if none found.
83
-
84
- ```javascript
85
- database: {
86
- postgres: {
87
- enable: true,
88
- management: 'discover', // Default
89
- }
90
- }
91
- ```
92
-
93
- **Discovery Priority**:
94
-
95
- 1. Frigg-managed cluster with matching service + stage tags
96
- 2. Any Frigg-managed cluster
97
- 3. First available Aurora PostgreSQL cluster
98
- 4. Creates new cluster if none found
99
-
100
- **Best For**: Development and staging environments where you want automatic setup.
101
-
102
- ---
103
-
104
- ### 2. Create-New Mode
105
-
106
- Always creates a new Aurora cluster, even if existing clusters are found.
107
-
108
- ```javascript
109
- database: {
110
- postgres: {
111
- enable: true,
112
- management: 'create-new',
113
-
114
- // Customization options
115
- databaseName: 'my_app_db',
116
- masterUsername: 'admin',
117
- engineVersion: '15.3',
118
- scaling: {
119
- minCapacity: 1.0,
120
- maxCapacity: 2.0,
121
- },
122
- backupRetentionDays: 14,
123
- deletionProtection: true,
124
- }
125
- }
126
- ```
127
-
128
- **Best For**: Production environments where you want dedicated database resources.
129
-
130
- ---
131
-
132
- ### 3. Use-Existing Mode
133
-
134
- Uses a specific existing Aurora cluster by identifier.
135
-
136
- ```javascript
137
- database: {
138
- postgres: {
139
- enable: true,
140
- management: 'use-existing',
141
-
142
- // Required: existing cluster identifier
143
- clusterIdentifier: 'my-existing-aurora-cluster',
144
-
145
- // Optional: secret ARN (discovered if not provided)
146
- secretArn: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:my-db-secret',
147
-
148
- // Database name to connect to
149
- databaseName: 'frigg_db',
150
- }
151
- }
152
- ```
153
-
154
- **Best For**: Shared database scenarios or when you manage Aurora outside of Frigg.
155
-
156
- ---
157
-
158
- ## Created AWS Resources
159
-
160
- When provisioning Aurora (`create-new` or `discover` mode without existing cluster), Frigg creates:
161
-
162
- ### 1. RDS DB Subnet Group
163
-
164
- - **Name**: `{service}-{stage}-db-subnet-group`
165
- - **Subnets**: Uses same private subnets as Lambda functions
166
- - **Purpose**: Defines which subnets Aurora can use
167
-
168
- ### 2. Security Group
169
-
170
- - **Name**: `{service}-{stage}-aurora-sg`
171
- - **Ingress**: Port 5432 from Lambda security group
172
- - **Purpose**: Allows Lambda → Aurora communication
173
-
174
- ### 3. Secrets Manager Secret
175
-
176
- - **Name**: `{service}-{stage}-aurora-credentials`
177
- - **Contents**: `{ username, password }`
178
- - **Purpose**: Stores database credentials securely
179
- - **Rotation**: Automatic (optional, can be configured)
180
-
181
- ### 4. Aurora Cluster
182
-
183
- - **Engine**: aurora-postgresql (version 15.3 default)
184
- - **Mode**: Provisioned (Serverless v2)
185
- - **Scaling**: 0.5-1.0 ACU (configurable)
186
- - **Backup**: 7-day retention (configurable)
187
- - **Multi-AZ**: Yes (high availability)
188
-
189
- ### 5. Aurora Instance
190
-
191
- - **Class**: db.serverless
192
- - **Cluster**: Attached to cluster above
193
- - **Public Access**: No (private subnet only)
194
-
195
- ### 6. IAM Permissions
196
-
197
- - **Secrets Manager**: GetSecretValue, DescribeSecret
198
- - **Purpose**: Lambda functions can retrieve credentials
199
-
200
- ---
201
-
202
- ## Cost Optimization
203
-
204
- ### Default Configuration (Most Cost-Efficient)
205
-
206
- ```javascript
207
- database: {
208
- postgres: {
209
- enable: true,
210
- // Uses defaults:
211
- // - 0.5 ACU minimum (scales to near-zero during idle)
212
- // - 1.0 ACU maximum
213
- // - No Performance Insights
214
- // - 7-day backup retention
215
- }
216
- }
217
- ```
218
-
219
- **Estimated Monthly Costs**:
220
-
221
- - **Idle/Low Traffic**: $15-30/month (0.5 ACU minimum)
222
- - **Moderate Traffic**: $30-60/month (0.5-1.0 ACU average)
223
- - **Storage**: $0.10/GB-month
224
- - **Backup Storage**: Free (within retention period)
225
-
226
- ### Production Configuration
227
-
228
- ```javascript
229
- database: {
230
- postgres: {
231
- enable: true,
232
- scaling: {
233
- minCapacity: 1.0, // Higher baseline for production
234
- maxCapacity: 4.0, // Handle traffic spikes
235
- },
236
- backupRetentionDays: 30, // Longer retention
237
- enablePerformanceInsights: true, // Monitoring
238
- deletionProtection: true, // Prevent accidental deletion
239
- }
240
- }
241
- ```
242
-
243
- **Estimated Monthly Costs**:
244
-
245
- - **Baseline**: $87/month (1.0 ACU minimum)
246
- - **Peak Traffic**: $348/month (4.0 ACU maximum)
247
- - **Performance Insights**: $7/month
248
-
249
- ### Cost-Saving Tips
250
-
251
- 1. **Use Aurora Serverless v2**: Scales to near-zero during idle periods
252
- 2. **Right-size ACU limits**: Start with defaults, increase only if needed
253
- 3. **Disable Performance Insights** in dev/staging
254
- 4. **Shorter backup retention** for non-production (7 days)
255
- 5. **Monitor CloudWatch metrics** to optimize scaling configuration
256
-
257
- ---
258
-
259
- ## Security Best Practices
260
-
261
- ### 1. Network Isolation
262
-
263
- - ✅ **Private Subnets Only**: Aurora deployed in private subnets (no internet access)
264
- - ✅ **Security Groups**: Restricts access to Lambda security group only
265
- - ✅ **VPC Endpoints**: Use VPC endpoints for AWS services (no NAT Gateway costs)
266
-
267
- ### 2. Credential Management
268
-
269
- - ✅ **Secrets Manager**: Never hardcode database passwords
270
- - ✅ **Auto-Rotation**: Enable automatic secret rotation (recommended)
271
- - ✅ **IAM Integration**: Lambda uses IAM role to access secrets
272
- - ❌ **Never commit** `DATABASE_URL` to source control
273
-
274
- ### 3. Access Control
275
-
276
- ```javascript
277
- // Lambda functions automatically get DATABASE_URL from Secrets Manager
278
- // No manual credential management required
279
-
280
- // Example: Prisma client automatically uses DATABASE_URL
281
- import { prismaClient } from '@friggframework/core/database/prisma';
282
-
283
- const users = await prismaClient.user.findMany();
284
- ```
285
-
286
- ### 4. Deletion Protection
287
-
288
- ```javascript
289
- database: {
290
- postgres: {
291
- deletionProtection: true, // Prevents accidental deletion
292
- }
293
- }
294
- ```
295
-
296
- **Important**: When enabled, you must manually disable deletion protection in AWS console before stack deletion.
297
-
298
- ---
299
-
300
- ## Environment Variables
301
-
302
- ### Automatically Set
303
-
304
- Frigg automatically sets these environment variables for Lambda functions:
305
-
306
- ```bash
307
- # Database connection (from Secrets Manager)
308
- DATABASE_URL=postgresql://user:pass@endpoint:5432/dbname
309
-
310
- # Database type (for Prisma client selection)
311
- DB_TYPE=postgresql
312
-
313
- # Discovery metadata (for debugging)
314
- AWS_DISCOVERY_AURORA_CLUSTER_ID=my-cluster
315
- AWS_DISCOVERY_AURORA_ENDPOINT=my-cluster.cluster-abc.us-east-1.rds.amazonaws.com
316
- AWS_DISCOVERY_AURORA_PORT=5432
317
- AWS_DISCOVERY_AURORA_SECRET_ARN=arn:aws:secretsmanager:...
318
- ```
319
-
320
- ### Usage in Lambda Functions
321
-
322
- ```javascript
323
- // No manual configuration needed!
324
- // DATABASE_URL is automatically available
325
-
326
- import { prismaClient } from '@friggframework/core/database/prisma';
327
-
328
- export async function handler(event, context) {
329
- // Prisma client uses DATABASE_URL automatically
330
- const result = await prismaClient.user.create({
331
- data: { email: 'user@example.com' },
332
- });
333
-
334
- return { statusCode: 200, body: JSON.stringify(result) };
335
- }
336
- ```
337
-
338
- ---
339
-
340
- ## Local Development
341
-
342
- ### Option 1: Docker Compose PostgreSQL
343
-
344
- ```yaml
345
- # docker-compose.yml
346
- version: '3.8'
347
- services:
348
- postgres:
349
- image: postgres:15
350
- environment:
351
- POSTGRES_USER: frigg_admin
352
- POSTGRES_PASSWORD: local_password
353
- POSTGRES_DB: frigg_db
354
- ports:
355
- - '5432:5432'
356
- volumes:
357
- - postgres_data:/var/lib/postgresql/data
358
-
359
- volumes:
360
- postgres_data:
361
- ```
362
-
363
- ```bash
364
- # .env (local development)
365
- DATABASE_URL=postgresql://frigg_admin:local_password@localhost:5432/frigg_db
366
- DB_TYPE=postgresql
367
- ```
368
-
369
- ### Option 2: Connect to AWS Aurora (Not Recommended)
370
-
371
- ```bash
372
- # .env (staging Aurora - for testing only)
373
- DATABASE_URL=postgresql://user:pass@staging-cluster.abc.us-east-1.rds.amazonaws.com:5432/frigg_db
374
- DB_TYPE=postgresql
375
- ```
376
-
377
- **Security Note**: Never commit Aurora credentials to source control. Use AWS SSO or parameter store for team access.
378
-
379
- ---
380
-
381
- ## Migration Guide
382
-
383
- ### From External PostgreSQL to Aurora
384
-
385
- 1. **Backup Existing Database**
386
-
387
- ```bash
388
- pg_dump -h old-host -U user -d dbname > backup.sql
389
- ```
390
-
391
- 2. **Deploy Aurora Cluster**
392
-
393
- ```javascript
394
- // backend/index.js
395
- database: {
396
- postgres: {
397
- enable: true,
398
- management: 'create-new',
399
- }
400
- }
401
- ```
402
-
403
- ```bash
404
- npm run frigg:deploy
405
- ```
406
-
407
- 3. **Restore to Aurora**
408
-
409
- ```bash
410
- # Get Aurora endpoint from AWS console or deployment output
411
- psql -h aurora-endpoint.us-east-1.rds.amazonaws.com -U frigg_admin -d frigg_db < backup.sql
412
- ```
413
-
414
- 4. **Run Migrations**
415
- ```bash
416
- npm run frigg:db:setup
417
- ```
418
-
419
- ### From MongoDB to PostgreSQL
420
-
421
- 1. **Add PostgreSQL Configuration**
422
-
423
- ```javascript
424
- database: {
425
- postgres: {
426
- enable: true,
427
- management: 'create-new',
428
- }
429
- }
430
- ```
431
-
432
- 2. **Run Prisma Migrations**
433
-
434
- ```bash
435
- # Generate Prisma PostgreSQL client
436
- npm run frigg:db:setup
437
- ```
438
-
439
- 3. **Data Migration Script** (custom per application)
440
-
441
- ```javascript
442
- // migrate-data.js
443
- const { MongoClient } = require('mongodb');
444
- const { prismaClient } = require('@friggframework/core/database/prisma');
445
-
446
- async function migrate() {
447
- const mongo = await MongoClient.connect(process.env.MONGO_URI);
448
- const users = await mongo.db().collection('users').find().toArray();
449
-
450
- for (const user of users) {
451
- await prismaClient.user.create({
452
- data: {
453
- id: user._id.toString(),
454
- email: user.email,
455
- // ... map fields
456
- },
457
- });
458
- }
459
-
460
- await mongo.close();
461
- }
462
-
463
- migrate().catch(console.error);
464
- ```
465
-
466
- ---
467
-
468
- ## Troubleshooting
469
-
470
- ### Issue: "No Aurora cluster found"
471
-
472
- **Error**:
473
-
474
- ```
475
- No Aurora cluster found in discovery mode. Set management to "create-new"...
476
- ```
477
-
478
- **Solution**:
479
-
480
- 1. Check VPC is enabled: `vpc.enable: true`
481
- 2. Set management mode: `management: 'create-new'`
482
- 3. Or provide cluster identifier: `clusterIdentifier: 'my-cluster'`
483
-
484
- ---
485
-
486
- ### Issue: "Timeout connecting to database"
487
-
488
- **Symptoms**: Lambda functions timeout when connecting to Aurora
489
-
490
- **Possible Causes**:
491
-
492
- 1. **Security Group Misconfiguration**
493
-
494
- - Check Lambda SG can access Aurora SG on port 5432
495
- - Verify Aurora SG allows inbound from Lambda SG
496
-
497
- 2. **VPC/Subnet Issues**
498
-
499
- - Ensure Lambda and Aurora in same VPC
500
- - Verify Aurora in private subnets
501
- - Check route tables allow internal VPC traffic
502
-
503
- 3. **Secret Not Found**
504
- - Verify Secrets Manager secret exists
505
- - Check IAM role has secretsmanager:GetSecretValue permission
506
-
507
- **Debug Steps**:
508
-
509
- ```bash
510
- # Check Aurora cluster status
511
- aws rds describe-db-clusters --db-cluster-identifier my-cluster
512
-
513
- # Check security groups
514
- aws ec2 describe-security-groups --group-ids sg-xxx
515
-
516
- # Test Lambda → Aurora connectivity (requires VPC endpoint or NAT)
517
- aws lambda invoke --function-name test-db-connection output.json
518
- ```
519
-
520
- ---
521
-
522
- ### Issue: "Insufficient capacity"
523
-
524
- **Error**:
525
-
526
- ```
527
- Cannot create Aurora cluster: InsufficientDBInstanceCapacity
528
- ```
529
-
530
- **Solution**:
531
-
532
- 1. Try different availability zones
533
- 2. Change instance class (though Serverless v2 shouldn't have this issue)
534
- 3. Contact AWS support for capacity increase
535
-
536
- ---
537
-
538
- ### Issue: "Cost unexpectedly high"
539
-
540
- **Symptoms**: Aurora costs higher than expected
541
-
542
- **Investigation**:
543
-
544
- 1. **Check ACU Usage**:
545
-
546
- ```bash
547
- # CloudWatch metric: ServerlessDatabaseCapacity
548
- aws cloudwatch get-metric-statistics \
549
- --namespace AWS/RDS \
550
- --metric-name ServerlessDatabaseCapacity \
551
- --dimensions Name=DBClusterIdentifier,Value=my-cluster \
552
- --start-time 2024-01-01T00:00:00Z \
553
- --end-time 2024-01-02T00:00:00Z \
554
- --period 3600 \
555
- --statistics Average
556
- ```
557
-
558
- 2. **Review Scaling Configuration**:
559
-
560
- - Lower `maxCapacity` if traffic spikes are rare
561
- - Increase `minCapacity` only if cold starts are an issue
562
-
563
- 3. **Check for Long-Running Connections**:
564
-
565
- - Aurora doesn't scale down if connections are open
566
- - Review application connection pooling
567
-
568
- 4. **Disable Performance Insights** in non-production
569
-
570
- ---
571
-
572
- ## Advanced Configuration
573
-
574
- ### Custom Backup Window
575
-
576
- ```javascript
577
- database: {
578
- postgres: {
579
- enable: true,
580
- backupRetentionDays: 30,
581
- preferredBackupWindow: '02:00-03:00', // UTC
582
- }
583
- }
584
- ```
585
-
586
- ### Enhanced Monitoring
587
-
588
- ```javascript
589
- database: {
590
- postgres: {
591
- enable: true,
592
- enablePerformanceInsights: true,
593
- // Performance Insights retention: 7 days (default) or 731 days
594
- }
595
- }
596
- ```
597
-
598
- ### Custom Engine Version
599
-
600
- ```javascript
601
- database: {
602
- postgres: {
603
- enable: true,
604
- engineVersion: '14.6', // Default: 15.3
605
- }
606
- }
607
- ```
608
-
609
- ### Read Replicas (Not Supported Yet)
610
-
611
- Frigg currently provisions a single Aurora instance. For read replicas:
612
-
613
- 1. Manually add instances in AWS console
614
- 2. Or create custom CloudFormation resources in `backend/infrastructure.js`
615
-
616
- ---
617
-
618
- ## Reference
619
-
620
- ### Supported PostgreSQL Versions
621
-
622
- - 15.3 (recommended, default)
623
- - 15.2
624
- - 14.6
625
- - 14.5
626
- - 13.9
627
-
628
- Check [Aurora PostgreSQL Releases](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraPostgreSQLReleaseNotes/AuroraPostgreSQL.Updates.html) for latest versions.
629
-
630
- ---
631
-
632
- ## Related Documentation
633
-
634
- - [VPC Configuration Guide](VPC-CONFIGURATION.md)
635
- - [Secrets Manager Integration](SECRETS-MANAGER.md)
636
- - [Database Migrations](../frigg-cli/DB-SETUP.md)
637
- - [AWS Discovery Troubleshooting](AWS-DISCOVERY-TROUBLESHOOTING.md)
638
-
639
- ---
640
-
641
- ## Support
642
-
643
- - **Issues**: [GitHub Issues](https://github.com/friggframework/frigg/issues)
644
- - **Documentation**: [Frigg Framework Docs](https://docs.friggframework.org)
645
- - **Community**: [Slack Channel](https://friggframework.org/#contact)