@stacksjs/ts-cloud-core 0.1.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/LICENSE.md +21 -0
- package/README.md +321 -0
- package/package.json +31 -0
- package/src/advanced-features.test.ts +465 -0
- package/src/aws/cloudformation.ts +421 -0
- package/src/aws/cloudfront.ts +158 -0
- package/src/aws/credentials.test.ts +132 -0
- package/src/aws/credentials.ts +545 -0
- package/src/aws/index.ts +87 -0
- package/src/aws/s3.test.ts +188 -0
- package/src/aws/s3.ts +1088 -0
- package/src/aws/signature.test.ts +670 -0
- package/src/aws/signature.ts +1155 -0
- package/src/backup/disaster-recovery.test.ts +726 -0
- package/src/backup/disaster-recovery.ts +500 -0
- package/src/backup/index.ts +34 -0
- package/src/backup/manager.test.ts +498 -0
- package/src/backup/manager.ts +432 -0
- package/src/cicd/circleci.ts +430 -0
- package/src/cicd/github-actions.ts +424 -0
- package/src/cicd/gitlab-ci.ts +255 -0
- package/src/cicd/index.ts +8 -0
- package/src/cli/history.ts +396 -0
- package/src/cli/index.ts +10 -0
- package/src/cli/progress.ts +458 -0
- package/src/cli/repl.ts +454 -0
- package/src/cli/suggestions.ts +327 -0
- package/src/cli/table.test.ts +319 -0
- package/src/cli/table.ts +332 -0
- package/src/cloudformation/builder.test.ts +327 -0
- package/src/cloudformation/builder.ts +378 -0
- package/src/cloudformation/builders/api-gateway.ts +449 -0
- package/src/cloudformation/builders/cache.ts +334 -0
- package/src/cloudformation/builders/cdn.ts +278 -0
- package/src/cloudformation/builders/compute.ts +485 -0
- package/src/cloudformation/builders/database.ts +392 -0
- package/src/cloudformation/builders/functions.ts +343 -0
- package/src/cloudformation/builders/messaging.ts +140 -0
- package/src/cloudformation/builders/monitoring.ts +300 -0
- package/src/cloudformation/builders/network.ts +264 -0
- package/src/cloudformation/builders/queue.ts +147 -0
- package/src/cloudformation/builders/security.ts +399 -0
- package/src/cloudformation/builders/storage.ts +285 -0
- package/src/cloudformation/index.ts +30 -0
- package/src/cloudformation/types.ts +173 -0
- package/src/compliance/aws-config.ts +543 -0
- package/src/compliance/cloudtrail.ts +376 -0
- package/src/compliance/compliance.test.ts +423 -0
- package/src/compliance/guardduty.ts +446 -0
- package/src/compliance/index.ts +66 -0
- package/src/compliance/security-hub.ts +456 -0
- package/src/containers/build-optimization.ts +416 -0
- package/src/containers/containers.test.ts +508 -0
- package/src/containers/image-scanning.ts +360 -0
- package/src/containers/index.ts +9 -0
- package/src/containers/registry.ts +293 -0
- package/src/containers/service-mesh.ts +520 -0
- package/src/database/database.test.ts +762 -0
- package/src/database/index.ts +9 -0
- package/src/database/migrations.ts +444 -0
- package/src/database/performance.ts +528 -0
- package/src/database/replicas.ts +534 -0
- package/src/database/users.ts +494 -0
- package/src/dependency-graph.ts +143 -0
- package/src/deployment/ab-testing.ts +582 -0
- package/src/deployment/blue-green.ts +452 -0
- package/src/deployment/canary.ts +500 -0
- package/src/deployment/deployment.test.ts +526 -0
- package/src/deployment/index.ts +61 -0
- package/src/deployment/progressive.ts +62 -0
- package/src/dns/dns.test.ts +641 -0
- package/src/dns/dnssec.ts +315 -0
- package/src/dns/index.ts +8 -0
- package/src/dns/resolver.ts +496 -0
- package/src/dns/routing.ts +593 -0
- package/src/email/advanced/analytics.ts +445 -0
- package/src/email/advanced/index.ts +11 -0
- package/src/email/advanced/rules.ts +465 -0
- package/src/email/advanced/scheduling.ts +352 -0
- package/src/email/advanced/search.ts +412 -0
- package/src/email/advanced/shared-mailboxes.ts +404 -0
- package/src/email/advanced/templates.ts +455 -0
- package/src/email/advanced/threading.ts +281 -0
- package/src/email/analytics.ts +467 -0
- package/src/email/bounce-handling.ts +425 -0
- package/src/email/email.test.ts +431 -0
- package/src/email/handlers/__tests__/inbound.test.ts +38 -0
- package/src/email/handlers/__tests__/outbound.test.ts +37 -0
- package/src/email/handlers/converter.ts +227 -0
- package/src/email/handlers/feedback.ts +228 -0
- package/src/email/handlers/inbound.ts +169 -0
- package/src/email/handlers/outbound.ts +178 -0
- package/src/email/index.ts +15 -0
- package/src/email/reputation.ts +303 -0
- package/src/email/templates.ts +352 -0
- package/src/errors/index.test.ts +434 -0
- package/src/errors/index.ts +416 -0
- package/src/health-checks/index.ts +40 -0
- package/src/index.ts +360 -0
- package/src/intrinsic-functions.ts +118 -0
- package/src/lambda/concurrency.ts +330 -0
- package/src/lambda/destinations.ts +345 -0
- package/src/lambda/dlq.ts +425 -0
- package/src/lambda/index.ts +11 -0
- package/src/lambda/lambda.test.ts +840 -0
- package/src/lambda/layers.ts +263 -0
- package/src/lambda/versions.ts +376 -0
- package/src/lambda/vpc.ts +399 -0
- package/src/local/config.ts +114 -0
- package/src/local/index.ts +6 -0
- package/src/local/mock-aws.ts +351 -0
- package/src/modules/ai.ts +340 -0
- package/src/modules/api.ts +478 -0
- package/src/modules/auth.ts +805 -0
- package/src/modules/cache.ts +417 -0
- package/src/modules/cdn.ts +1062 -0
- package/src/modules/communication.ts +1094 -0
- package/src/modules/compute.ts +3348 -0
- package/src/modules/database.ts +554 -0
- package/src/modules/deployment.ts +1079 -0
- package/src/modules/dns.ts +337 -0
- package/src/modules/email.ts +1538 -0
- package/src/modules/filesystem.ts +515 -0
- package/src/modules/index.ts +32 -0
- package/src/modules/messaging.ts +486 -0
- package/src/modules/monitoring.ts +2086 -0
- package/src/modules/network.ts +664 -0
- package/src/modules/parameter-store.ts +325 -0
- package/src/modules/permissions.ts +1081 -0
- package/src/modules/phone.ts +494 -0
- package/src/modules/queue.ts +1260 -0
- package/src/modules/redirects.ts +464 -0
- package/src/modules/registry.ts +699 -0
- package/src/modules/search.ts +401 -0
- package/src/modules/secrets.ts +416 -0
- package/src/modules/security.ts +731 -0
- package/src/modules/sms.ts +389 -0
- package/src/modules/storage.ts +1120 -0
- package/src/modules/workflow.ts +680 -0
- package/src/multi-account/config.ts +521 -0
- package/src/multi-account/index.ts +7 -0
- package/src/multi-account/manager.ts +427 -0
- package/src/multi-region/cross-region.ts +410 -0
- package/src/multi-region/index.ts +8 -0
- package/src/multi-region/manager.ts +483 -0
- package/src/multi-region/regions.ts +435 -0
- package/src/network-security/index.ts +48 -0
- package/src/observability/index.ts +9 -0
- package/src/observability/logs.ts +522 -0
- package/src/observability/metrics.ts +460 -0
- package/src/observability/observability.test.ts +782 -0
- package/src/observability/synthetics.ts +568 -0
- package/src/observability/xray.ts +358 -0
- package/src/phone/advanced/analytics.ts +349 -0
- package/src/phone/advanced/callbacks.ts +428 -0
- package/src/phone/advanced/index.ts +8 -0
- package/src/phone/advanced/ivr-builder.ts +504 -0
- package/src/phone/advanced/recording.ts +310 -0
- package/src/phone/handlers/__tests__/incoming-call.test.ts +40 -0
- package/src/phone/handlers/incoming-call.ts +117 -0
- package/src/phone/handlers/missed-call.ts +116 -0
- package/src/phone/handlers/voicemail.ts +179 -0
- package/src/phone/index.ts +9 -0
- package/src/presets/api-backend.ts +134 -0
- package/src/presets/data-pipeline.ts +204 -0
- package/src/presets/extend.test.ts +295 -0
- package/src/presets/extend.ts +297 -0
- package/src/presets/fullstack-app.ts +144 -0
- package/src/presets/index.ts +27 -0
- package/src/presets/jamstack.ts +135 -0
- package/src/presets/microservices.ts +167 -0
- package/src/presets/ml-api.ts +208 -0
- package/src/presets/nodejs-server.ts +104 -0
- package/src/presets/nodejs-serverless.ts +114 -0
- package/src/presets/realtime-app.ts +184 -0
- package/src/presets/static-site.ts +64 -0
- package/src/presets/traditional-web-app.ts +339 -0
- package/src/presets/wordpress.ts +138 -0
- package/src/preview/github.test.ts +249 -0
- package/src/preview/github.ts +297 -0
- package/src/preview/index.ts +37 -0
- package/src/preview/manager.test.ts +440 -0
- package/src/preview/manager.ts +326 -0
- package/src/preview/notifications.test.ts +582 -0
- package/src/preview/notifications.ts +341 -0
- package/src/queue/batch-processing.ts +402 -0
- package/src/queue/dlq-monitoring.ts +402 -0
- package/src/queue/fifo.ts +342 -0
- package/src/queue/index.ts +9 -0
- package/src/queue/management.ts +428 -0
- package/src/queue/queue.test.ts +429 -0
- package/src/resource-mgmt/index.ts +39 -0
- package/src/resource-naming.ts +62 -0
- package/src/s3/index.ts +523 -0
- package/src/schema/cloud-config.schema.json +554 -0
- package/src/schema/index.ts +68 -0
- package/src/security/certificate-manager.ts +492 -0
- package/src/security/index.ts +9 -0
- package/src/security/scanning.ts +545 -0
- package/src/security/secrets-manager.ts +476 -0
- package/src/security/secrets-rotation.ts +456 -0
- package/src/security/security.test.ts +738 -0
- package/src/sms/advanced/ab-testing.ts +389 -0
- package/src/sms/advanced/analytics.ts +336 -0
- package/src/sms/advanced/campaigns.ts +523 -0
- package/src/sms/advanced/chatbot.ts +224 -0
- package/src/sms/advanced/index.ts +10 -0
- package/src/sms/advanced/link-tracking.ts +248 -0
- package/src/sms/advanced/mms.ts +308 -0
- package/src/sms/handlers/__tests__/send.test.ts +40 -0
- package/src/sms/handlers/delivery-status.ts +133 -0
- package/src/sms/handlers/receive.ts +162 -0
- package/src/sms/handlers/send.ts +174 -0
- package/src/sms/index.ts +9 -0
- package/src/stack-diff.ts +389 -0
- package/src/static-site/index.ts +85 -0
- package/src/template-builder.ts +110 -0
- package/src/template-validator.ts +574 -0
- package/src/utils/cache.ts +291 -0
- package/src/utils/diff.ts +269 -0
- package/src/utils/hash.ts +227 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/parallel.ts +294 -0
- package/src/validators/credentials.test.ts +274 -0
- package/src/validators/credentials.ts +233 -0
- package/src/validators/quotas.test.ts +434 -0
- package/src/validators/quotas.ts +217 -0
- package/test/ai.test.ts +327 -0
- package/test/api.test.ts +511 -0
- package/test/auth.test.ts +632 -0
- package/test/cache.test.ts +406 -0
- package/test/cdn.test.ts +247 -0
- package/test/compute.test.ts +861 -0
- package/test/database.test.ts +523 -0
- package/test/deployment.test.ts +499 -0
- package/test/dns.test.ts +270 -0
- package/test/email.test.ts +439 -0
- package/test/filesystem.test.ts +382 -0
- package/test/integration.test.ts +350 -0
- package/test/messaging.test.ts +514 -0
- package/test/monitoring.test.ts +634 -0
- package/test/network.test.ts +425 -0
- package/test/permissions.test.ts +488 -0
- package/test/queue.test.ts +484 -0
- package/test/registry.test.ts +306 -0
- package/test/security.test.ts +462 -0
- package/test/storage.test.ts +463 -0
- package/test/template-validator.test.ts +559 -0
- package/test/workflow.test.ts +592 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voicemail Lambda Handler
|
|
3
|
+
*
|
|
4
|
+
* Processes voicemail recordings:
|
|
5
|
+
* - Processes voicemail recordings from S3
|
|
6
|
+
* - Transcribes using Amazon Transcribe
|
|
7
|
+
* - Sends notification with transcription
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const handler = `
|
|
11
|
+
const { S3Client, GetObjectCommand, PutObjectCommand } = require('@aws-sdk/client-s3');
|
|
12
|
+
const { TranscribeClient, StartTranscriptionJobCommand, GetTranscriptionJobCommand } = require('@aws-sdk/client-transcribe');
|
|
13
|
+
const { SNSClient, PublishCommand } = require('@aws-sdk/client-sns');
|
|
14
|
+
const { DynamoDBClient, UpdateItemCommand } = require('@aws-sdk/client-dynamodb');
|
|
15
|
+
|
|
16
|
+
const s3 = new S3Client({});
|
|
17
|
+
const transcribe = new TranscribeClient({});
|
|
18
|
+
const sns = new SNSClient({});
|
|
19
|
+
const dynamodb = new DynamoDBClient({});
|
|
20
|
+
|
|
21
|
+
exports.handler = async (event) => {
|
|
22
|
+
console.log('Voicemail event:', JSON.stringify(event, null, 2));
|
|
23
|
+
|
|
24
|
+
const notificationTopicArn = process.env.NOTIFICATION_TOPIC_ARN;
|
|
25
|
+
const voicemailBucket = process.env.VOICEMAIL_BUCKET;
|
|
26
|
+
const callLogTable = process.env.CALL_LOG_TABLE;
|
|
27
|
+
const transcriptionEnabled = process.env.TRANSCRIPTION_ENABLED === 'true';
|
|
28
|
+
|
|
29
|
+
for (const record of event.Records) {
|
|
30
|
+
try {
|
|
31
|
+
const s3Event = record.s3 || {};
|
|
32
|
+
const bucket = s3Event.bucket?.name || voicemailBucket;
|
|
33
|
+
const key = decodeURIComponent(s3Event.object?.key?.replace(/\\+/g, ' ') || '');
|
|
34
|
+
|
|
35
|
+
if (!key.includes('voicemail') || !key.endsWith('.wav')) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log(\`Processing voicemail: \${key}\`);
|
|
40
|
+
|
|
41
|
+
// Extract metadata from key (format: voicemails/{contactId}/{timestamp}.wav)
|
|
42
|
+
const parts = key.split('/');
|
|
43
|
+
const contactId = parts[1] || 'unknown';
|
|
44
|
+
const filename = parts[parts.length - 1];
|
|
45
|
+
const timestamp = filename.replace('.wav', '');
|
|
46
|
+
|
|
47
|
+
// Get voicemail metadata if exists
|
|
48
|
+
let metadata = {};
|
|
49
|
+
try {
|
|
50
|
+
const metaResult = await s3.send(new GetObjectCommand({
|
|
51
|
+
Bucket: bucket,
|
|
52
|
+
Key: key.replace('.wav', '.json'),
|
|
53
|
+
}));
|
|
54
|
+
metadata = JSON.parse(await metaResult.Body.transformToString());
|
|
55
|
+
} catch {
|
|
56
|
+
// No metadata file
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let transcription = null;
|
|
60
|
+
|
|
61
|
+
// Start transcription if enabled
|
|
62
|
+
if (transcriptionEnabled) {
|
|
63
|
+
const jobName = \`voicemail-\${contactId}-\${Date.now()}\`;
|
|
64
|
+
|
|
65
|
+
await transcribe.send(new StartTranscriptionJobCommand({
|
|
66
|
+
TranscriptionJobName: jobName,
|
|
67
|
+
LanguageCode: 'en-US',
|
|
68
|
+
MediaFormat: 'wav',
|
|
69
|
+
Media: {
|
|
70
|
+
MediaFileUri: \`s3://\${bucket}/\${key}\`,
|
|
71
|
+
},
|
|
72
|
+
OutputBucketName: bucket,
|
|
73
|
+
OutputKey: key.replace('.wav', '-transcript.json'),
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
// Wait for transcription (with timeout)
|
|
77
|
+
let attempts = 0;
|
|
78
|
+
const maxAttempts = 30; // 5 minutes max
|
|
79
|
+
|
|
80
|
+
while (attempts < maxAttempts) {
|
|
81
|
+
await new Promise(resolve => setTimeout(resolve, 10000)); // 10 seconds
|
|
82
|
+
|
|
83
|
+
const jobResult = await transcribe.send(new GetTranscriptionJobCommand({
|
|
84
|
+
TranscriptionJobName: jobName,
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
const status = jobResult.TranscriptionJob?.TranscriptionJobStatus;
|
|
88
|
+
|
|
89
|
+
if (status === 'COMPLETED') {
|
|
90
|
+
// Get transcription result
|
|
91
|
+
try {
|
|
92
|
+
const transcriptResult = await s3.send(new GetObjectCommand({
|
|
93
|
+
Bucket: bucket,
|
|
94
|
+
Key: key.replace('.wav', '-transcript.json'),
|
|
95
|
+
}));
|
|
96
|
+
const transcriptData = JSON.parse(await transcriptResult.Body.transformToString());
|
|
97
|
+
transcription = transcriptData.results?.transcripts?.[0]?.transcript || '';
|
|
98
|
+
} catch (err) {
|
|
99
|
+
console.error('Error getting transcription:', err.message);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
} else if (status === 'FAILED') {
|
|
103
|
+
console.error('Transcription failed');
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
attempts++;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Update call log
|
|
112
|
+
if (callLogTable && contactId !== 'unknown') {
|
|
113
|
+
await dynamodb.send(new UpdateItemCommand({
|
|
114
|
+
TableName: callLogTable,
|
|
115
|
+
Key: {
|
|
116
|
+
contactId: { S: contactId },
|
|
117
|
+
},
|
|
118
|
+
UpdateExpression: 'SET voicemailKey = :key, voicemailTranscript = :transcript, voicemailAt = :at',
|
|
119
|
+
ExpressionAttributeValues: {
|
|
120
|
+
':key': { S: key },
|
|
121
|
+
':transcript': { S: transcription || '' },
|
|
122
|
+
':at': { S: new Date().toISOString() },
|
|
123
|
+
},
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Save voicemail metadata
|
|
128
|
+
await s3.send(new PutObjectCommand({
|
|
129
|
+
Bucket: bucket,
|
|
130
|
+
Key: key.replace('.wav', '-metadata.json'),
|
|
131
|
+
Body: JSON.stringify({
|
|
132
|
+
contactId,
|
|
133
|
+
callerNumber: metadata.callerNumber || 'unknown',
|
|
134
|
+
calledNumber: metadata.calledNumber || 'unknown',
|
|
135
|
+
duration: metadata.duration || 0,
|
|
136
|
+
recordedAt: timestamp,
|
|
137
|
+
processedAt: new Date().toISOString(),
|
|
138
|
+
transcription,
|
|
139
|
+
audioKey: key,
|
|
140
|
+
}, null, 2),
|
|
141
|
+
ContentType: 'application/json',
|
|
142
|
+
}));
|
|
143
|
+
|
|
144
|
+
// Send notification
|
|
145
|
+
if (notificationTopicArn) {
|
|
146
|
+
await sns.send(new PublishCommand({
|
|
147
|
+
TopicArn: notificationTopicArn,
|
|
148
|
+
Subject: 'New Voicemail',
|
|
149
|
+
Message: JSON.stringify({
|
|
150
|
+
type: 'voicemail',
|
|
151
|
+
contactId,
|
|
152
|
+
from: metadata.callerNumber || 'unknown',
|
|
153
|
+
to: metadata.calledNumber || 'unknown',
|
|
154
|
+
duration: metadata.duration || 0,
|
|
155
|
+
transcription: transcription || '(transcription not available)',
|
|
156
|
+
audioUrl: \`s3://\${bucket}/\${key}\`,
|
|
157
|
+
timestamp: new Date().toISOString(),
|
|
158
|
+
}, null, 2),
|
|
159
|
+
MessageAttributes: {
|
|
160
|
+
eventType: {
|
|
161
|
+
DataType: 'String',
|
|
162
|
+
StringValue: 'voicemail',
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
console.log(\`Processed voicemail: \${contactId}\`);
|
|
169
|
+
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.error('Error processing voicemail:', error);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return { statusCode: 200, body: 'OK' };
|
|
176
|
+
};
|
|
177
|
+
`
|
|
178
|
+
|
|
179
|
+
export default handler
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { CloudConfig } from '@stacksjs/ts-cloud-types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* API-Only Backend Preset
|
|
5
|
+
* Perfect for: REST APIs, GraphQL APIs, mobile backends
|
|
6
|
+
* Includes: API Gateway + Lambda functions + DynamoDB
|
|
7
|
+
*/
|
|
8
|
+
export function createApiBackendPreset(options: {
|
|
9
|
+
name: string
|
|
10
|
+
slug: string
|
|
11
|
+
domain?: string
|
|
12
|
+
}): Partial<CloudConfig> {
|
|
13
|
+
const { name, slug, domain } = options
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
project: {
|
|
17
|
+
name,
|
|
18
|
+
slug,
|
|
19
|
+
region: 'us-east-1',
|
|
20
|
+
},
|
|
21
|
+
mode: 'serverless',
|
|
22
|
+
environments: {
|
|
23
|
+
production: {
|
|
24
|
+
type: 'production',
|
|
25
|
+
domain,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
infrastructure: {
|
|
29
|
+
apiGateway: {
|
|
30
|
+
type: 'HTTP', // HTTP API is cheaper and simpler
|
|
31
|
+
cors: {
|
|
32
|
+
allowOrigins: ['*'],
|
|
33
|
+
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
|
|
34
|
+
allowHeaders: ['Content-Type', 'Authorization'],
|
|
35
|
+
maxAge: 3600,
|
|
36
|
+
},
|
|
37
|
+
customDomain: domain ? {
|
|
38
|
+
domain,
|
|
39
|
+
certificateArn: 'TO_BE_GENERATED',
|
|
40
|
+
} : undefined,
|
|
41
|
+
throttling: {
|
|
42
|
+
rateLimit: 10000,
|
|
43
|
+
burstLimit: 5000,
|
|
44
|
+
},
|
|
45
|
+
authorizer: {
|
|
46
|
+
type: 'JWT',
|
|
47
|
+
identitySource: '$request.header.Authorization',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
functions: {
|
|
51
|
+
users: {
|
|
52
|
+
runtime: 'nodejs20.x',
|
|
53
|
+
handler: 'dist/api/users.handler',
|
|
54
|
+
memory: 512,
|
|
55
|
+
timeout: 30,
|
|
56
|
+
events: [{
|
|
57
|
+
type: 'http',
|
|
58
|
+
path: '/users',
|
|
59
|
+
method: 'GET',
|
|
60
|
+
}, {
|
|
61
|
+
type: 'http',
|
|
62
|
+
path: '/users',
|
|
63
|
+
method: 'POST',
|
|
64
|
+
}],
|
|
65
|
+
},
|
|
66
|
+
products: {
|
|
67
|
+
runtime: 'nodejs20.x',
|
|
68
|
+
handler: 'dist/api/products.handler',
|
|
69
|
+
memory: 512,
|
|
70
|
+
timeout: 30,
|
|
71
|
+
events: [{
|
|
72
|
+
type: 'http',
|
|
73
|
+
path: '/products',
|
|
74
|
+
method: 'GET',
|
|
75
|
+
}],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
databases: {
|
|
79
|
+
dynamodb: {
|
|
80
|
+
tables: {
|
|
81
|
+
[`${slug}-users`]: {
|
|
82
|
+
partitionKey: { name: 'userId', type: 'S' },
|
|
83
|
+
billingMode: 'PAY_PER_REQUEST',
|
|
84
|
+
streamEnabled: true,
|
|
85
|
+
pointInTimeRecovery: true,
|
|
86
|
+
globalSecondaryIndexes: [{
|
|
87
|
+
name: 'EmailIndex',
|
|
88
|
+
partitionKey: { name: 'email', type: 'S' },
|
|
89
|
+
projection: 'ALL',
|
|
90
|
+
}],
|
|
91
|
+
},
|
|
92
|
+
[`${slug}-products`]: {
|
|
93
|
+
partitionKey: { name: 'productId', type: 'S' },
|
|
94
|
+
sortKey: { name: 'category', type: 'S' },
|
|
95
|
+
billingMode: 'PAY_PER_REQUEST',
|
|
96
|
+
streamEnabled: false,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
cache: {
|
|
102
|
+
elasticache: {
|
|
103
|
+
nodeType: 'cache.t3.micro',
|
|
104
|
+
numCacheNodes: 1,
|
|
105
|
+
engine: 'redis',
|
|
106
|
+
engineVersion: '7.0',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
security: {
|
|
110
|
+
certificate: domain ? {
|
|
111
|
+
domain,
|
|
112
|
+
validationMethod: 'DNS',
|
|
113
|
+
} : undefined,
|
|
114
|
+
waf: {
|
|
115
|
+
enabled: true,
|
|
116
|
+
rules: ['rateLimit', 'sqlInjection'],
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
monitoring: {
|
|
120
|
+
alarms: [{
|
|
121
|
+
metric: 'Errors',
|
|
122
|
+
threshold: 10,
|
|
123
|
+
period: 300,
|
|
124
|
+
evaluationPeriods: 1,
|
|
125
|
+
}, {
|
|
126
|
+
metric: 'Duration',
|
|
127
|
+
threshold: 3000, // 3 seconds
|
|
128
|
+
period: 300,
|
|
129
|
+
evaluationPeriods: 2,
|
|
130
|
+
}],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import type { CloudConfig } from '@stacksjs/ts-cloud-types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Data Pipeline Preset
|
|
5
|
+
* Perfect for: ETL pipelines, data processing, analytics workflows
|
|
6
|
+
* Includes: Kinesis + Lambda + S3 + Athena + Glue
|
|
7
|
+
*/
|
|
8
|
+
export function createDataPipelinePreset(options: {
|
|
9
|
+
name: string
|
|
10
|
+
slug: string
|
|
11
|
+
retentionDays?: number
|
|
12
|
+
}): Partial<CloudConfig> {
|
|
13
|
+
const {
|
|
14
|
+
name,
|
|
15
|
+
slug,
|
|
16
|
+
retentionDays = 7,
|
|
17
|
+
} = options
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
project: {
|
|
21
|
+
name,
|
|
22
|
+
slug,
|
|
23
|
+
region: 'us-east-1',
|
|
24
|
+
},
|
|
25
|
+
mode: 'serverless',
|
|
26
|
+
infrastructure: {
|
|
27
|
+
streaming: {
|
|
28
|
+
dataStream: {
|
|
29
|
+
name: `${slug}-stream`,
|
|
30
|
+
shardCount: 2,
|
|
31
|
+
retentionPeriod: retentionDays * 24, // Convert to hours
|
|
32
|
+
encryption: true,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
storage: {
|
|
36
|
+
raw: {
|
|
37
|
+
public: false,
|
|
38
|
+
versioning: true,
|
|
39
|
+
encryption: true,
|
|
40
|
+
intelligentTiering: true,
|
|
41
|
+
lifecycleRules: [{
|
|
42
|
+
id: 'ArchiveOldData',
|
|
43
|
+
enabled: true,
|
|
44
|
+
transitions: [{
|
|
45
|
+
days: 30,
|
|
46
|
+
storageClass: 'GLACIER',
|
|
47
|
+
}, {
|
|
48
|
+
days: 90,
|
|
49
|
+
storageClass: 'DEEP_ARCHIVE',
|
|
50
|
+
}],
|
|
51
|
+
}],
|
|
52
|
+
},
|
|
53
|
+
processed: {
|
|
54
|
+
public: false,
|
|
55
|
+
versioning: true,
|
|
56
|
+
encryption: true,
|
|
57
|
+
intelligentTiering: true,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
functions: {
|
|
61
|
+
'stream-processor': {
|
|
62
|
+
runtime: 'nodejs20.x',
|
|
63
|
+
handler: 'dist/processors/stream.handler',
|
|
64
|
+
memory: 2048,
|
|
65
|
+
timeout: 300, // 5 minutes for batch processing
|
|
66
|
+
events: [{
|
|
67
|
+
type: 'kinesis',
|
|
68
|
+
streamName: `${slug}-stream`,
|
|
69
|
+
batchSize: 1000,
|
|
70
|
+
startingPosition: 'LATEST',
|
|
71
|
+
parallelizationFactor: 10,
|
|
72
|
+
}],
|
|
73
|
+
},
|
|
74
|
+
transformer: {
|
|
75
|
+
runtime: 'nodejs20.x',
|
|
76
|
+
handler: 'dist/processors/transform.handler',
|
|
77
|
+
memory: 3008,
|
|
78
|
+
timeout: 900, // 15 minutes
|
|
79
|
+
events: [{
|
|
80
|
+
type: 's3',
|
|
81
|
+
bucket: `${slug}-raw`,
|
|
82
|
+
prefix: 'incoming/',
|
|
83
|
+
}],
|
|
84
|
+
},
|
|
85
|
+
aggregator: {
|
|
86
|
+
runtime: 'nodejs20.x',
|
|
87
|
+
handler: 'dist/processors/aggregate.handler',
|
|
88
|
+
memory: 2048,
|
|
89
|
+
timeout: 600, // 10 minutes
|
|
90
|
+
events: [{
|
|
91
|
+
type: 'schedule',
|
|
92
|
+
expression: 'cron(0 * * * ? *)', // Every hour
|
|
93
|
+
}],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
analytics: {
|
|
97
|
+
athena: {
|
|
98
|
+
database: `${slug}_analytics`,
|
|
99
|
+
workgroup: `${slug}-workgroup`,
|
|
100
|
+
outputBucket: `${slug}-query-results`,
|
|
101
|
+
tables: [{
|
|
102
|
+
name: 'raw_events',
|
|
103
|
+
location: `s3://${slug}-raw/events/`,
|
|
104
|
+
format: 'parquet',
|
|
105
|
+
partitionKeys: ['year', 'month', 'day'],
|
|
106
|
+
}, {
|
|
107
|
+
name: 'processed_events',
|
|
108
|
+
location: `s3://${slug}-processed/events/`,
|
|
109
|
+
format: 'parquet',
|
|
110
|
+
partitionKeys: ['year', 'month', 'day'],
|
|
111
|
+
}],
|
|
112
|
+
},
|
|
113
|
+
glue: {
|
|
114
|
+
crawlers: [{
|
|
115
|
+
name: `${slug}-crawler`,
|
|
116
|
+
databaseName: `${slug}_analytics`,
|
|
117
|
+
s3Targets: [
|
|
118
|
+
`s3://${slug}-raw/`,
|
|
119
|
+
`s3://${slug}-processed/`,
|
|
120
|
+
],
|
|
121
|
+
schedule: 'cron(0 2 * * ? *)', // Daily at 2 AM
|
|
122
|
+
}],
|
|
123
|
+
jobs: [{
|
|
124
|
+
name: `${slug}-etl-job`,
|
|
125
|
+
scriptLocation: `s3://${slug}-scripts/etl.py`,
|
|
126
|
+
role: `${slug}-glue-role`,
|
|
127
|
+
maxCapacity: 10,
|
|
128
|
+
timeout: 120, // 2 hours
|
|
129
|
+
}],
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
databases: {
|
|
133
|
+
dynamodb: {
|
|
134
|
+
tables: {
|
|
135
|
+
[`${slug}-metadata`]: {
|
|
136
|
+
partitionKey: { name: 'pipelineId', type: 'S' },
|
|
137
|
+
sortKey: { name: 'timestamp', type: 'S' },
|
|
138
|
+
billingMode: 'PAY_PER_REQUEST',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
queues: {
|
|
144
|
+
failedJobs: {
|
|
145
|
+
fifo: false,
|
|
146
|
+
visibilityTimeout: 900, // 15 minutes
|
|
147
|
+
messageRetentionPeriod: 1209600, // 14 days
|
|
148
|
+
deadLetterQueue: true,
|
|
149
|
+
maxReceiveCount: 3,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
workflow: {
|
|
153
|
+
pipelines: [{
|
|
154
|
+
name: `${slug}-daily-pipeline`,
|
|
155
|
+
type: 'stepFunctions',
|
|
156
|
+
definition: {
|
|
157
|
+
StartAt: 'ExtractData',
|
|
158
|
+
States: {
|
|
159
|
+
ExtractData: {
|
|
160
|
+
Type: 'Task',
|
|
161
|
+
Resource: 'arn:aws:states:::lambda:invoke',
|
|
162
|
+
Next: 'TransformData',
|
|
163
|
+
},
|
|
164
|
+
TransformData: {
|
|
165
|
+
Type: 'Task',
|
|
166
|
+
Resource: 'arn:aws:states:::lambda:invoke',
|
|
167
|
+
Next: 'LoadData',
|
|
168
|
+
},
|
|
169
|
+
LoadData: {
|
|
170
|
+
Type: 'Task',
|
|
171
|
+
Resource: 'arn:aws:states:::lambda:invoke',
|
|
172
|
+
End: true,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
schedule: 'cron(0 0 * * ? *)', // Daily at midnight
|
|
177
|
+
}],
|
|
178
|
+
},
|
|
179
|
+
monitoring: {
|
|
180
|
+
dashboard: {
|
|
181
|
+
name: `${slug}-pipeline`,
|
|
182
|
+
widgets: [{
|
|
183
|
+
type: 'metric',
|
|
184
|
+
metrics: [
|
|
185
|
+
'KinesisIncomingRecords',
|
|
186
|
+
'LambdaInvocations',
|
|
187
|
+
'S3ObjectsCreated',
|
|
188
|
+
'GlueJobsSucceeded',
|
|
189
|
+
],
|
|
190
|
+
}],
|
|
191
|
+
},
|
|
192
|
+
alarms: [{
|
|
193
|
+
metric: 'LambdaErrors',
|
|
194
|
+
threshold: 10,
|
|
195
|
+
evaluationPeriods: 1,
|
|
196
|
+
}, {
|
|
197
|
+
metric: 'KinesisIteratorAge',
|
|
198
|
+
threshold: 60000, // 1 minute
|
|
199
|
+
evaluationPeriods: 2,
|
|
200
|
+
}],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
}
|
|
204
|
+
}
|