@friggframework/devtools 2.0.0-next.27 → 2.0.0-next.29
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/frigg-cli/build-command/index.js +4 -2
- package/frigg-cli/deploy-command/index.js +5 -2
- package/frigg-cli/generate-iam-command.js +115 -0
- package/frigg-cli/index.js +11 -1
- package/infrastructure/AWS-DISCOVERY-TROUBLESHOOTING.md +245 -0
- package/infrastructure/AWS-IAM-CREDENTIAL-NEEDS.md +596 -0
- package/infrastructure/DEPLOYMENT-INSTRUCTIONS.md +268 -0
- package/infrastructure/GENERATE-IAM-DOCS.md +253 -0
- package/infrastructure/IAM-POLICY-TEMPLATES.md +176 -0
- package/infrastructure/README-TESTING.md +332 -0
- package/infrastructure/README.md +421 -0
- package/infrastructure/WEBSOCKET-CONFIGURATION.md +105 -0
- package/infrastructure/__tests__/fixtures/mock-aws-resources.js +391 -0
- package/infrastructure/__tests__/helpers/test-utils.js +277 -0
- package/infrastructure/aws-discovery.js +568 -0
- package/infrastructure/aws-discovery.test.js +373 -0
- package/infrastructure/build-time-discovery.js +206 -0
- package/infrastructure/build-time-discovery.test.js +375 -0
- package/infrastructure/create-frigg-infrastructure.js +2 -2
- package/infrastructure/frigg-deployment-iam-stack.yaml +379 -0
- package/infrastructure/iam-generator.js +687 -0
- package/infrastructure/iam-generator.test.js +169 -0
- package/infrastructure/iam-policy-basic.json +212 -0
- package/infrastructure/iam-policy-full.json +282 -0
- package/infrastructure/integration.test.js +383 -0
- package/infrastructure/run-discovery.js +110 -0
- package/infrastructure/serverless-template.js +537 -212
- package/infrastructure/serverless-template.test.js +541 -0
- package/management-ui/dist/assets/FriggLogo-B7Xx8ZW1.svg +1 -0
- package/management-ui/dist/assets/index-BA21WgFa.js +1221 -0
- package/management-ui/dist/assets/index-CbM64Oba.js +1221 -0
- package/management-ui/dist/assets/index-CkvseXTC.css +1 -0
- package/management-ui/dist/index.html +14 -0
- package/package.json +9 -5
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
# Frigg Infrastructure
|
|
2
|
+
|
|
3
|
+
This directory contains the infrastructure-as-code templates and utilities for deploying Frigg applications to AWS.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install dependencies
|
|
9
|
+
npm install
|
|
10
|
+
|
|
11
|
+
# Run infrastructure tests
|
|
12
|
+
npm test
|
|
13
|
+
|
|
14
|
+
# Deploy basic infrastructure
|
|
15
|
+
frigg deploy --stage production
|
|
16
|
+
|
|
17
|
+
# Deploy with Phase 3 features
|
|
18
|
+
frigg deploy --stage production --enable-phase3
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Directory Structure
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
infrastructure/
|
|
25
|
+
├── README.md # This file
|
|
26
|
+
├── PHASE3-DEPLOYMENT-GUIDE.md # Phase 3 deployment guide
|
|
27
|
+
├── AWS-DISCOVERY-TROUBLESHOOTING.md # AWS discovery troubleshooting
|
|
28
|
+
├── DEPLOYMENT-INSTRUCTIONS.md # General deployment instructions
|
|
29
|
+
├── README-TESTING.md # Testing strategy documentation
|
|
30
|
+
├──
|
|
31
|
+
├── cloudformation/ # CloudFormation templates
|
|
32
|
+
│ ├── monitoring-infrastructure.yaml # Enhanced monitoring (Phase 3)
|
|
33
|
+
│ ├── cdn-infrastructure.yaml # CDN and UI distribution (Phase 3)
|
|
34
|
+
│ ├── codegen-infrastructure.yaml # Code generation services (Phase 3)
|
|
35
|
+
│ ├── alerting-infrastructure.yaml # Advanced alerting (Phase 3)
|
|
36
|
+
│ └── deployment-pipeline.yaml # CI/CD pipeline (Phase 3)
|
|
37
|
+
├──
|
|
38
|
+
├── aws-discovery.js # AWS resource discovery utility
|
|
39
|
+
├── build-time-discovery.js # Build-time discovery integration
|
|
40
|
+
├── serverless-template.js # Serverless configuration generator
|
|
41
|
+
├── iam-generator.js # IAM policy generator
|
|
42
|
+
├── create-frigg-infrastructure.js # Infrastructure creation utility
|
|
43
|
+
├── run-discovery.js # Discovery runner script
|
|
44
|
+
├──
|
|
45
|
+
├── __tests__/ # Test files
|
|
46
|
+
│ ├── fixtures/ # Test fixtures and mock data
|
|
47
|
+
│ └── helpers/ # Test helper utilities
|
|
48
|
+
├── aws-discovery.test.js # AWS discovery tests
|
|
49
|
+
├── build-time-discovery.test.js # Build-time discovery tests
|
|
50
|
+
├── serverless-template.test.js # Serverless template tests
|
|
51
|
+
├── iam-generator.test.js # IAM generator tests
|
|
52
|
+
├── integration.test.js # End-to-end integration tests
|
|
53
|
+
└── ... # Additional test files
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Infrastructure Components
|
|
57
|
+
|
|
58
|
+
### Core Infrastructure (Phase 1-2)
|
|
59
|
+
|
|
60
|
+
#### 1. Serverless Template Generator (`serverless-template.js`)
|
|
61
|
+
|
|
62
|
+
Generates complete serverless.yml configurations with:
|
|
63
|
+
- VPC configuration and resource discovery
|
|
64
|
+
- KMS encryption for field-level encryption
|
|
65
|
+
- SSM Parameter Store integration
|
|
66
|
+
- Integration-specific functions and queues
|
|
67
|
+
- WebSocket support for real-time features
|
|
68
|
+
|
|
69
|
+
#### 2. AWS Discovery (`aws-discovery.js`)
|
|
70
|
+
|
|
71
|
+
Automatically discovers existing AWS resources:
|
|
72
|
+
- Default VPC and security groups
|
|
73
|
+
- Private subnets for Lambda functions
|
|
74
|
+
- Customer-managed KMS keys
|
|
75
|
+
- Route tables for VPC endpoints
|
|
76
|
+
|
|
77
|
+
#### 3. Build-Time Discovery (`build-time-discovery.js`)
|
|
78
|
+
|
|
79
|
+
Integrates AWS discovery into the build process:
|
|
80
|
+
- Pre-build hook for serverless deployments
|
|
81
|
+
- Environment variable injection
|
|
82
|
+
- Template variable replacement
|
|
83
|
+
- Error handling and fallback values
|
|
84
|
+
|
|
85
|
+
### Phase 3 Infrastructure
|
|
86
|
+
|
|
87
|
+
#### 1. Enhanced Monitoring (`cloudformation/monitoring-infrastructure.yaml`)
|
|
88
|
+
|
|
89
|
+
Production-ready monitoring with:
|
|
90
|
+
- Code generation service monitoring
|
|
91
|
+
- UI distribution monitoring
|
|
92
|
+
- Advanced CloudWatch dashboards
|
|
93
|
+
- Custom metrics and alarms
|
|
94
|
+
|
|
95
|
+
#### 2. CDN Infrastructure (`cloudformation/cdn-infrastructure.yaml`)
|
|
96
|
+
|
|
97
|
+
CloudFront distribution for UI packages:
|
|
98
|
+
- S3 bucket for multi-framework UI packages
|
|
99
|
+
- CloudFront distribution with custom domains
|
|
100
|
+
- Lambda function for package deployment
|
|
101
|
+
- API Gateway for package management
|
|
102
|
+
|
|
103
|
+
#### 3. Code Generation Infrastructure (`cloudformation/codegen-infrastructure.yaml`)
|
|
104
|
+
|
|
105
|
+
Serverless code generation platform:
|
|
106
|
+
- SQS queue for generation requests
|
|
107
|
+
- Lambda function with AI/ML integration
|
|
108
|
+
- DynamoDB tracking table
|
|
109
|
+
- S3 storage for templates and generated code
|
|
110
|
+
- ElastiCache for template caching
|
|
111
|
+
|
|
112
|
+
#### 4. Advanced Alerting (`cloudformation/alerting-infrastructure.yaml`)
|
|
113
|
+
|
|
114
|
+
Multi-channel alerting system:
|
|
115
|
+
- Multiple SNS topics for alert severity levels
|
|
116
|
+
- Lambda function for alert processing
|
|
117
|
+
- PagerDuty and Slack integration
|
|
118
|
+
- Composite alarms for system health
|
|
119
|
+
- Advanced metrics collection
|
|
120
|
+
|
|
121
|
+
#### 5. Deployment Pipeline (`cloudformation/deployment-pipeline.yaml`)
|
|
122
|
+
|
|
123
|
+
CI/CD pipeline for automated deployments:
|
|
124
|
+
- CodePipeline with GitHub integration
|
|
125
|
+
- CodeBuild projects for backend and UI
|
|
126
|
+
- Multi-stage deployment workflow
|
|
127
|
+
- Integration testing and approval gates
|
|
128
|
+
|
|
129
|
+
## Configuration Options
|
|
130
|
+
|
|
131
|
+
### App Definition Structure
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
const appDefinition = {
|
|
135
|
+
// Basic configuration
|
|
136
|
+
name: 'my-frigg-app',
|
|
137
|
+
provider: 'aws',
|
|
138
|
+
|
|
139
|
+
// VPC configuration
|
|
140
|
+
vpc: {
|
|
141
|
+
enable: true,
|
|
142
|
+
createNew: false, // Use existing VPC (default)
|
|
143
|
+
securityGroupIds: [...], // Optional: custom security groups
|
|
144
|
+
subnetIds: [...], // Optional: custom subnets
|
|
145
|
+
enableVPCEndpoints: true // Optional: create VPC endpoints
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
// KMS encryption
|
|
149
|
+
encryption: {
|
|
150
|
+
useDefaultKMSForFieldLevelEncryption: true
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
// SSM Parameter Store
|
|
154
|
+
ssm: {
|
|
155
|
+
enable: true
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
// WebSocket support (Phase 3)
|
|
159
|
+
websockets: {
|
|
160
|
+
enable: true
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
// Integrations
|
|
164
|
+
integrations: [
|
|
165
|
+
{ Definition: { name: 'hubspot' } },
|
|
166
|
+
{ Definition: { name: 'salesforce' } }
|
|
167
|
+
]
|
|
168
|
+
};
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Environment Variables
|
|
172
|
+
|
|
173
|
+
The infrastructure system uses environment variables for AWS resource references:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Automatically set by AWS discovery
|
|
177
|
+
AWS_DISCOVERY_VPC_ID=vpc-12345678
|
|
178
|
+
AWS_DISCOVERY_SECURITY_GROUP_ID=sg-12345678
|
|
179
|
+
AWS_DISCOVERY_SUBNET_ID_1=subnet-12345678
|
|
180
|
+
AWS_DISCOVERY_SUBNET_ID_2=subnet-87654321
|
|
181
|
+
AWS_DISCOVERY_ROUTE_TABLE_ID=rtb-12345678
|
|
182
|
+
AWS_DISCOVERY_KMS_KEY_ID=arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012
|
|
183
|
+
|
|
184
|
+
# Set by serverless framework
|
|
185
|
+
AWS_REGION=us-east-1
|
|
186
|
+
STAGE=production
|
|
187
|
+
SERVICE_NAME=my-frigg-app
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Usage Examples
|
|
191
|
+
|
|
192
|
+
### Basic Deployment
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
const { composeServerlessDefinition } = require('./serverless-template');
|
|
196
|
+
|
|
197
|
+
const appDefinition = {
|
|
198
|
+
name: 'my-app',
|
|
199
|
+
integrations: [
|
|
200
|
+
{ Definition: { name: 'hubspot' } }
|
|
201
|
+
]
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const serverlessConfig = await composeServerlessDefinition(appDefinition);
|
|
205
|
+
// Use serverlessConfig for deployment
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### VPC-Enabled Deployment
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
const appDefinition = {
|
|
212
|
+
name: 'secure-app',
|
|
213
|
+
vpc: { enable: true },
|
|
214
|
+
encryption: { useDefaultKMSForFieldLevelEncryption: true },
|
|
215
|
+
ssm: { enable: true },
|
|
216
|
+
integrations: [
|
|
217
|
+
{ Definition: { name: 'salesforce' } }
|
|
218
|
+
]
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const serverlessConfig = await composeServerlessDefinition(appDefinition);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Phase 3 Deployment with WebSockets
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
const appDefinition = {
|
|
228
|
+
name: 'realtime-app',
|
|
229
|
+
websockets: { enable: true },
|
|
230
|
+
vpc: { enable: true },
|
|
231
|
+
integrations: [
|
|
232
|
+
{ Definition: { name: 'slack' } }
|
|
233
|
+
]
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const serverlessConfig = await composeServerlessDefinition(appDefinition);
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Testing
|
|
240
|
+
|
|
241
|
+
### Running Tests
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# Run all infrastructure tests
|
|
245
|
+
npm test
|
|
246
|
+
|
|
247
|
+
# Run specific test suites
|
|
248
|
+
npm test aws-discovery.test.js
|
|
249
|
+
npm test serverless-template.test.js
|
|
250
|
+
npm test integration.test.js
|
|
251
|
+
|
|
252
|
+
# Run with coverage
|
|
253
|
+
npm test -- --coverage
|
|
254
|
+
|
|
255
|
+
# Run in watch mode
|
|
256
|
+
npm test -- --watch
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Test Categories
|
|
260
|
+
|
|
261
|
+
1. **Unit Tests**: Test individual components
|
|
262
|
+
- AWS discovery utilities
|
|
263
|
+
- Serverless template generation
|
|
264
|
+
- IAM policy generation
|
|
265
|
+
|
|
266
|
+
2. **Integration Tests**: Test end-to-end workflows
|
|
267
|
+
- Complete discovery and template generation
|
|
268
|
+
- Plugin integration
|
|
269
|
+
- Phase 3 infrastructure validation
|
|
270
|
+
|
|
271
|
+
3. **Performance Tests**: Validate infrastructure limits
|
|
272
|
+
- CloudFormation template sizes
|
|
273
|
+
- Resource count limits
|
|
274
|
+
- Cross-stack dependencies
|
|
275
|
+
|
|
276
|
+
### Mock Data
|
|
277
|
+
|
|
278
|
+
Tests use mock AWS resources to avoid real AWS API calls:
|
|
279
|
+
|
|
280
|
+
```javascript
|
|
281
|
+
const mockAWSResources = {
|
|
282
|
+
defaultVpcId: 'vpc-12345678',
|
|
283
|
+
defaultSecurityGroupId: 'sg-12345678',
|
|
284
|
+
privateSubnetId1: 'subnet-private-1',
|
|
285
|
+
privateSubnetId2: 'subnet-private-2',
|
|
286
|
+
defaultKmsKeyId: 'arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012'
|
|
287
|
+
};
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Security
|
|
291
|
+
|
|
292
|
+
### IAM Permissions
|
|
293
|
+
|
|
294
|
+
The infrastructure requires specific IAM permissions for AWS resource discovery and deployment:
|
|
295
|
+
|
|
296
|
+
- **EC2**: Describe VPCs, subnets, security groups, route tables
|
|
297
|
+
- **KMS**: List keys, describe keys
|
|
298
|
+
- **STS**: Get caller identity
|
|
299
|
+
- **CloudFormation**: Full access for stack operations
|
|
300
|
+
- **Lambda**: Function management
|
|
301
|
+
- **API Gateway**: API management
|
|
302
|
+
- **S3**: Bucket and object operations (including tagging)
|
|
303
|
+
- **DynamoDB**: Table operations
|
|
304
|
+
- **SQS**: Queue operations
|
|
305
|
+
- **SNS**: Topic operations
|
|
306
|
+
- **CloudWatch**: Metrics and alarms
|
|
307
|
+
- **IAM**: Role and policy management
|
|
308
|
+
|
|
309
|
+
### Best Practices
|
|
310
|
+
|
|
311
|
+
1. **Least Privilege**: IAM roles have minimal required permissions
|
|
312
|
+
2. **Encryption**: All data encrypted at rest and in transit
|
|
313
|
+
3. **VPC Security**: Lambda functions in private subnets when needed
|
|
314
|
+
4. **Access Control**: S3 buckets block public access by default
|
|
315
|
+
5. **Audit Logging**: CloudTrail integration for API calls
|
|
316
|
+
|
|
317
|
+
## Troubleshooting
|
|
318
|
+
|
|
319
|
+
### Common Issues
|
|
320
|
+
|
|
321
|
+
#### AWS Discovery Failures
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
# Check AWS credentials
|
|
325
|
+
aws sts get-caller-identity
|
|
326
|
+
|
|
327
|
+
# Verify region configuration
|
|
328
|
+
echo $AWS_REGION
|
|
329
|
+
|
|
330
|
+
# Test VPC discovery
|
|
331
|
+
node -e "
|
|
332
|
+
const { AWSDiscovery } = require('./aws-discovery');
|
|
333
|
+
const discovery = new AWSDiscovery('us-east-1');
|
|
334
|
+
discovery.findDefaultVpc().then(console.log).catch(console.error);
|
|
335
|
+
"
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
#### Serverless Deployment Issues
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
# Enable debug logging
|
|
342
|
+
SLS_DEBUG=true serverless deploy
|
|
343
|
+
|
|
344
|
+
# Check generated template
|
|
345
|
+
serverless print
|
|
346
|
+
|
|
347
|
+
# Validate CloudFormation template
|
|
348
|
+
aws cloudformation validate-template --template-body file://template.json
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### Infrastructure Test Failures
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
# Run specific failing test
|
|
355
|
+
npm test -- --testNamePattern="should discover all AWS resources"
|
|
356
|
+
|
|
357
|
+
# Debug with verbose output
|
|
358
|
+
npm test -- --verbose --silent=false
|
|
359
|
+
|
|
360
|
+
# Check test environment
|
|
361
|
+
npm run test:debug
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Performance Optimization
|
|
365
|
+
|
|
366
|
+
#### Lambda Cold Starts
|
|
367
|
+
- Use provisioned concurrency for critical functions
|
|
368
|
+
- Optimize function size and dependencies
|
|
369
|
+
- Monitor cold start metrics
|
|
370
|
+
|
|
371
|
+
#### VPC Performance
|
|
372
|
+
- Use VPC endpoints to reduce NAT Gateway costs
|
|
373
|
+
- Monitor ENI creation/deletion times
|
|
374
|
+
- Consider Lambda@Edge for global distribution
|
|
375
|
+
|
|
376
|
+
#### Cost Optimization
|
|
377
|
+
- Use S3 Intelligent Tiering
|
|
378
|
+
- Configure CloudWatch log retention
|
|
379
|
+
- Monitor and alert on unexpected usage
|
|
380
|
+
|
|
381
|
+
## Contributing
|
|
382
|
+
|
|
383
|
+
### Adding New Infrastructure Components
|
|
384
|
+
|
|
385
|
+
1. Create CloudFormation template in `cloudformation/`
|
|
386
|
+
2. Add validation tests in `__tests__/`
|
|
387
|
+
3. Update integration tests
|
|
388
|
+
4. Document in deployment guide
|
|
389
|
+
5. Add to CI/CD pipeline
|
|
390
|
+
|
|
391
|
+
### Testing Guidelines
|
|
392
|
+
|
|
393
|
+
1. Mock all AWS API calls
|
|
394
|
+
2. Test both success and failure scenarios
|
|
395
|
+
3. Validate CloudFormation template syntax
|
|
396
|
+
4. Test cross-stack dependencies
|
|
397
|
+
5. Include performance and security tests
|
|
398
|
+
|
|
399
|
+
### Documentation
|
|
400
|
+
|
|
401
|
+
1. Update this README for new features
|
|
402
|
+
2. Add examples to deployment guide
|
|
403
|
+
3. Document troubleshooting steps
|
|
404
|
+
4. Include security considerations
|
|
405
|
+
|
|
406
|
+
## Support
|
|
407
|
+
|
|
408
|
+
- **Documentation**: See `PHASE3-DEPLOYMENT-GUIDE.md` for detailed deployment instructions
|
|
409
|
+
- **Testing**: See `README-TESTING.md` for testing strategy
|
|
410
|
+
- **Troubleshooting**: See `AWS-DISCOVERY-TROUBLESHOOTING.md` for common issues
|
|
411
|
+
- **Issues**: Create GitHub issues for bugs and feature requests
|
|
412
|
+
- **Discussions**: Use GitHub Discussions for questions and ideas
|
|
413
|
+
|
|
414
|
+
## Related Documentation
|
|
415
|
+
|
|
416
|
+
- [Phase 3 Deployment Guide](./PHASE3-DEPLOYMENT-GUIDE.md)
|
|
417
|
+
- [Testing Strategy](./README-TESTING.md)
|
|
418
|
+
- [AWS Discovery Troubleshooting](./AWS-DISCOVERY-TROUBLESHOOTING.md)
|
|
419
|
+
- [IAM Policy Templates](./IAM-POLICY-TEMPLATES.md)
|
|
420
|
+
- [VPC Configuration](./VPC-CONFIGURATION.md)
|
|
421
|
+
- [WebSocket Configuration](./WEBSOCKET-CONFIGURATION.md)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# WebSocket Configuration for Frigg Applications
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
WebSockets in Frigg applications are now **disabled by default** and can be enabled through the AppDefinition configuration. This allows applications that don't need real-time communication to avoid deploying unnecessary WebSocket infrastructure.
|
|
6
|
+
|
|
7
|
+
## Enabling WebSockets
|
|
8
|
+
|
|
9
|
+
To enable WebSocket support in your Frigg application, add the `websockets` configuration to your AppDefinition:
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
// backend/index.js
|
|
13
|
+
const appDefinition = {
|
|
14
|
+
integrations: [YourIntegration],
|
|
15
|
+
websockets: {
|
|
16
|
+
enable: true // Enable WebSocket support
|
|
17
|
+
},
|
|
18
|
+
// ... other configuration
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
Definition: appDefinition,
|
|
23
|
+
};
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## What Happens When WebSockets Are Enabled
|
|
27
|
+
|
|
28
|
+
When you set `websockets.enable: true`, the following resources are deployed:
|
|
29
|
+
|
|
30
|
+
1. **WebSocket API Gateway** - AWS API Gateway WebSocket endpoint
|
|
31
|
+
2. **Lambda Functions** - Handlers for `$connect`, `$disconnect`, and `$default` routes
|
|
32
|
+
3. **Database Collection** - MongoDB collection to store active WebSocket connections
|
|
33
|
+
4. **Environment Variable** - `WEBSOCKET_API_ENDPOINT` is automatically configured
|
|
34
|
+
|
|
35
|
+
## Using WebSockets in Your Application
|
|
36
|
+
|
|
37
|
+
Once enabled, you can use the `WebsocketConnection` model to send messages to connected clients:
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
const { WebsocketConnection } = require('@friggframework/core');
|
|
41
|
+
|
|
42
|
+
// Get all active connections and send a message
|
|
43
|
+
const connections = await WebsocketConnection.getActiveConnections();
|
|
44
|
+
for (const connection of connections) {
|
|
45
|
+
await connection.send({
|
|
46
|
+
type: 'update',
|
|
47
|
+
data: { message: 'Hello from server!' }
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Default Behavior (WebSockets Disabled)
|
|
53
|
+
|
|
54
|
+
When websockets are disabled (the default):
|
|
55
|
+
- No WebSocket infrastructure is deployed
|
|
56
|
+
- `WebsocketConnection.getActiveConnections()` returns an empty array
|
|
57
|
+
- No `WEBSOCKET_API_ENDPOINT` environment variable is set
|
|
58
|
+
- No additional Lambda functions or API Gateway resources are created
|
|
59
|
+
|
|
60
|
+
## Use Cases for WebSockets
|
|
61
|
+
|
|
62
|
+
Enable WebSockets when you need:
|
|
63
|
+
- Real-time updates for integration sync status
|
|
64
|
+
- Live streaming of data processing progress
|
|
65
|
+
- Push notifications to connected clients
|
|
66
|
+
- Real-time collaboration features
|
|
67
|
+
|
|
68
|
+
## Cost Considerations
|
|
69
|
+
|
|
70
|
+
Disabling WebSockets by default helps reduce costs by:
|
|
71
|
+
- Avoiding API Gateway WebSocket charges when not needed
|
|
72
|
+
- Reducing Lambda function invocations
|
|
73
|
+
- Eliminating unnecessary database operations for connection management
|
|
74
|
+
|
|
75
|
+
## Migration Guide
|
|
76
|
+
|
|
77
|
+
If you have an existing Frigg application that uses WebSockets:
|
|
78
|
+
|
|
79
|
+
1. Add the websockets configuration to your AppDefinition:
|
|
80
|
+
```javascript
|
|
81
|
+
websockets: {
|
|
82
|
+
enable: true
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
2. Redeploy your application:
|
|
87
|
+
```bash
|
|
88
|
+
npx frigg deploy
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Your WebSocket functionality will continue to work as before.
|
|
92
|
+
|
|
93
|
+
## Troubleshooting
|
|
94
|
+
|
|
95
|
+
### WebSocket Connection Errors
|
|
96
|
+
If you see errors related to WebSocket connections, ensure:
|
|
97
|
+
1. WebSockets are enabled in your AppDefinition
|
|
98
|
+
2. The application has been redeployed after enabling WebSockets
|
|
99
|
+
3. The `WEBSOCKET_API_ENDPOINT` environment variable is set (automatically done during deployment)
|
|
100
|
+
|
|
101
|
+
### WebsocketConnection.getActiveConnections() Returns Empty Array
|
|
102
|
+
This is expected behavior when:
|
|
103
|
+
- WebSockets are disabled (default)
|
|
104
|
+
- No clients are currently connected
|
|
105
|
+
- The `WEBSOCKET_API_ENDPOINT` environment variable is not set
|