@stacksjs/ts-cloud-core 0.1.2 → 0.1.6
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/README.md +98 -13
- package/package.json +12 -3
- package/src/advanced-features.test.ts +0 -465
- package/src/aws/cloudformation.ts +0 -421
- package/src/aws/cloudfront.ts +0 -158
- package/src/aws/credentials.test.ts +0 -132
- package/src/aws/credentials.ts +0 -545
- package/src/aws/index.ts +0 -87
- package/src/aws/s3.test.ts +0 -188
- package/src/aws/s3.ts +0 -1088
- package/src/aws/signature.test.ts +0 -670
- package/src/aws/signature.ts +0 -1155
- package/src/backup/disaster-recovery.test.ts +0 -726
- package/src/backup/disaster-recovery.ts +0 -500
- package/src/backup/index.ts +0 -34
- package/src/backup/manager.test.ts +0 -498
- package/src/backup/manager.ts +0 -432
- package/src/cicd/circleci.ts +0 -430
- package/src/cicd/github-actions.ts +0 -424
- package/src/cicd/gitlab-ci.ts +0 -255
- package/src/cicd/index.ts +0 -8
- package/src/cli/history.ts +0 -396
- package/src/cli/index.ts +0 -10
- package/src/cli/progress.ts +0 -458
- package/src/cli/repl.ts +0 -454
- package/src/cli/suggestions.ts +0 -327
- package/src/cli/table.test.ts +0 -319
- package/src/cli/table.ts +0 -332
- package/src/cloudformation/builder.test.ts +0 -327
- package/src/cloudformation/builder.ts +0 -378
- package/src/cloudformation/builders/api-gateway.ts +0 -449
- package/src/cloudformation/builders/cache.ts +0 -334
- package/src/cloudformation/builders/cdn.ts +0 -278
- package/src/cloudformation/builders/compute.ts +0 -485
- package/src/cloudformation/builders/database.ts +0 -392
- package/src/cloudformation/builders/functions.ts +0 -343
- package/src/cloudformation/builders/messaging.ts +0 -140
- package/src/cloudformation/builders/monitoring.ts +0 -300
- package/src/cloudformation/builders/network.ts +0 -264
- package/src/cloudformation/builders/queue.ts +0 -147
- package/src/cloudformation/builders/security.ts +0 -399
- package/src/cloudformation/builders/storage.ts +0 -285
- package/src/cloudformation/index.ts +0 -30
- package/src/cloudformation/types.ts +0 -173
- package/src/compliance/aws-config.ts +0 -543
- package/src/compliance/cloudtrail.ts +0 -376
- package/src/compliance/compliance.test.ts +0 -423
- package/src/compliance/guardduty.ts +0 -446
- package/src/compliance/index.ts +0 -66
- package/src/compliance/security-hub.ts +0 -456
- package/src/containers/build-optimization.ts +0 -416
- package/src/containers/containers.test.ts +0 -508
- package/src/containers/image-scanning.ts +0 -360
- package/src/containers/index.ts +0 -9
- package/src/containers/registry.ts +0 -293
- package/src/containers/service-mesh.ts +0 -520
- package/src/database/database.test.ts +0 -762
- package/src/database/index.ts +0 -9
- package/src/database/migrations.ts +0 -444
- package/src/database/performance.ts +0 -528
- package/src/database/replicas.ts +0 -534
- package/src/database/users.ts +0 -494
- package/src/dependency-graph.ts +0 -143
- package/src/deployment/ab-testing.ts +0 -582
- package/src/deployment/blue-green.ts +0 -452
- package/src/deployment/canary.ts +0 -500
- package/src/deployment/deployment.test.ts +0 -526
- package/src/deployment/index.ts +0 -61
- package/src/deployment/progressive.ts +0 -62
- package/src/dns/dns.test.ts +0 -641
- package/src/dns/dnssec.ts +0 -315
- package/src/dns/index.ts +0 -8
- package/src/dns/resolver.ts +0 -496
- package/src/dns/routing.ts +0 -593
- package/src/email/advanced/analytics.ts +0 -445
- package/src/email/advanced/index.ts +0 -11
- package/src/email/advanced/rules.ts +0 -465
- package/src/email/advanced/scheduling.ts +0 -352
- package/src/email/advanced/search.ts +0 -412
- package/src/email/advanced/shared-mailboxes.ts +0 -404
- package/src/email/advanced/templates.ts +0 -455
- package/src/email/advanced/threading.ts +0 -281
- package/src/email/analytics.ts +0 -467
- package/src/email/bounce-handling.ts +0 -425
- package/src/email/email.test.ts +0 -431
- package/src/email/handlers/__tests__/inbound.test.ts +0 -38
- package/src/email/handlers/__tests__/outbound.test.ts +0 -37
- package/src/email/handlers/converter.ts +0 -227
- package/src/email/handlers/feedback.ts +0 -228
- package/src/email/handlers/inbound.ts +0 -169
- package/src/email/handlers/outbound.ts +0 -178
- package/src/email/index.ts +0 -15
- package/src/email/reputation.ts +0 -303
- package/src/email/templates.ts +0 -352
- package/src/errors/index.test.ts +0 -434
- package/src/errors/index.ts +0 -416
- package/src/health-checks/index.ts +0 -40
- package/src/index.ts +0 -360
- package/src/intrinsic-functions.ts +0 -118
- package/src/lambda/concurrency.ts +0 -330
- package/src/lambda/destinations.ts +0 -345
- package/src/lambda/dlq.ts +0 -425
- package/src/lambda/index.ts +0 -11
- package/src/lambda/lambda.test.ts +0 -840
- package/src/lambda/layers.ts +0 -263
- package/src/lambda/versions.ts +0 -376
- package/src/lambda/vpc.ts +0 -399
- package/src/local/config.ts +0 -114
- package/src/local/index.ts +0 -6
- package/src/local/mock-aws.ts +0 -351
- package/src/modules/ai.ts +0 -340
- package/src/modules/api.ts +0 -478
- package/src/modules/auth.ts +0 -805
- package/src/modules/cache.ts +0 -417
- package/src/modules/cdn.ts +0 -1062
- package/src/modules/communication.ts +0 -1094
- package/src/modules/compute.ts +0 -3348
- package/src/modules/database.ts +0 -554
- package/src/modules/deployment.ts +0 -1079
- package/src/modules/dns.ts +0 -337
- package/src/modules/email.ts +0 -1538
- package/src/modules/filesystem.ts +0 -515
- package/src/modules/index.ts +0 -32
- package/src/modules/messaging.ts +0 -486
- package/src/modules/monitoring.ts +0 -2086
- package/src/modules/network.ts +0 -664
- package/src/modules/parameter-store.ts +0 -325
- package/src/modules/permissions.ts +0 -1081
- package/src/modules/phone.ts +0 -494
- package/src/modules/queue.ts +0 -1260
- package/src/modules/redirects.ts +0 -464
- package/src/modules/registry.ts +0 -699
- package/src/modules/search.ts +0 -401
- package/src/modules/secrets.ts +0 -416
- package/src/modules/security.ts +0 -731
- package/src/modules/sms.ts +0 -389
- package/src/modules/storage.ts +0 -1120
- package/src/modules/workflow.ts +0 -680
- package/src/multi-account/config.ts +0 -521
- package/src/multi-account/index.ts +0 -7
- package/src/multi-account/manager.ts +0 -427
- package/src/multi-region/cross-region.ts +0 -410
- package/src/multi-region/index.ts +0 -8
- package/src/multi-region/manager.ts +0 -483
- package/src/multi-region/regions.ts +0 -435
- package/src/network-security/index.ts +0 -48
- package/src/observability/index.ts +0 -9
- package/src/observability/logs.ts +0 -522
- package/src/observability/metrics.ts +0 -460
- package/src/observability/observability.test.ts +0 -782
- package/src/observability/synthetics.ts +0 -568
- package/src/observability/xray.ts +0 -358
- package/src/phone/advanced/analytics.ts +0 -349
- package/src/phone/advanced/callbacks.ts +0 -428
- package/src/phone/advanced/index.ts +0 -8
- package/src/phone/advanced/ivr-builder.ts +0 -504
- package/src/phone/advanced/recording.ts +0 -310
- package/src/phone/handlers/__tests__/incoming-call.test.ts +0 -40
- package/src/phone/handlers/incoming-call.ts +0 -117
- package/src/phone/handlers/missed-call.ts +0 -116
- package/src/phone/handlers/voicemail.ts +0 -179
- package/src/phone/index.ts +0 -9
- package/src/presets/api-backend.ts +0 -134
- package/src/presets/data-pipeline.ts +0 -204
- package/src/presets/extend.test.ts +0 -295
- package/src/presets/extend.ts +0 -297
- package/src/presets/fullstack-app.ts +0 -144
- package/src/presets/index.ts +0 -27
- package/src/presets/jamstack.ts +0 -135
- package/src/presets/microservices.ts +0 -167
- package/src/presets/ml-api.ts +0 -208
- package/src/presets/nodejs-server.ts +0 -104
- package/src/presets/nodejs-serverless.ts +0 -114
- package/src/presets/realtime-app.ts +0 -184
- package/src/presets/static-site.ts +0 -64
- package/src/presets/traditional-web-app.ts +0 -339
- package/src/presets/wordpress.ts +0 -138
- package/src/preview/github.test.ts +0 -249
- package/src/preview/github.ts +0 -297
- package/src/preview/index.ts +0 -37
- package/src/preview/manager.test.ts +0 -440
- package/src/preview/manager.ts +0 -326
- package/src/preview/notifications.test.ts +0 -582
- package/src/preview/notifications.ts +0 -341
- package/src/queue/batch-processing.ts +0 -402
- package/src/queue/dlq-monitoring.ts +0 -402
- package/src/queue/fifo.ts +0 -342
- package/src/queue/index.ts +0 -9
- package/src/queue/management.ts +0 -428
- package/src/queue/queue.test.ts +0 -429
- package/src/resource-mgmt/index.ts +0 -39
- package/src/resource-naming.ts +0 -62
- package/src/s3/index.ts +0 -523
- package/src/schema/cloud-config.schema.json +0 -554
- package/src/schema/index.ts +0 -68
- package/src/security/certificate-manager.ts +0 -492
- package/src/security/index.ts +0 -9
- package/src/security/scanning.ts +0 -545
- package/src/security/secrets-manager.ts +0 -476
- package/src/security/secrets-rotation.ts +0 -456
- package/src/security/security.test.ts +0 -738
- package/src/sms/advanced/ab-testing.ts +0 -389
- package/src/sms/advanced/analytics.ts +0 -336
- package/src/sms/advanced/campaigns.ts +0 -523
- package/src/sms/advanced/chatbot.ts +0 -224
- package/src/sms/advanced/index.ts +0 -10
- package/src/sms/advanced/link-tracking.ts +0 -248
- package/src/sms/advanced/mms.ts +0 -308
- package/src/sms/handlers/__tests__/send.test.ts +0 -40
- package/src/sms/handlers/delivery-status.ts +0 -133
- package/src/sms/handlers/receive.ts +0 -162
- package/src/sms/handlers/send.ts +0 -174
- package/src/sms/index.ts +0 -9
- package/src/stack-diff.ts +0 -389
- package/src/static-site/index.ts +0 -85
- package/src/template-builder.ts +0 -110
- package/src/template-validator.ts +0 -574
- package/src/utils/cache.ts +0 -291
- package/src/utils/diff.ts +0 -269
- package/src/utils/hash.ts +0 -227
- package/src/utils/index.ts +0 -8
- package/src/utils/parallel.ts +0 -294
- package/src/validators/credentials.test.ts +0 -274
- package/src/validators/credentials.ts +0 -233
- package/src/validators/quotas.test.ts +0 -434
- package/src/validators/quotas.ts +0 -217
- package/test/ai.test.ts +0 -327
- package/test/api.test.ts +0 -511
- package/test/auth.test.ts +0 -632
- package/test/cache.test.ts +0 -406
- package/test/cdn.test.ts +0 -247
- package/test/compute.test.ts +0 -861
- package/test/database.test.ts +0 -523
- package/test/deployment.test.ts +0 -499
- package/test/dns.test.ts +0 -270
- package/test/email.test.ts +0 -439
- package/test/filesystem.test.ts +0 -382
- package/test/integration.test.ts +0 -350
- package/test/messaging.test.ts +0 -514
- package/test/monitoring.test.ts +0 -634
- package/test/network.test.ts +0 -425
- package/test/permissions.test.ts +0 -488
- package/test/queue.test.ts +0 -484
- package/test/registry.test.ts +0 -306
- package/test/security.test.ts +0 -462
- package/test/storage.test.ts +0 -463
- package/test/template-validator.test.ts +0 -559
- package/test/workflow.test.ts +0 -592
- package/tsconfig.json +0 -16
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
import type { CloudFormationBuilder } from '../builder'
|
|
2
|
-
import { Fn } from '../types'
|
|
3
|
-
|
|
4
|
-
export interface SecurityConfig {
|
|
5
|
-
certificate?: {
|
|
6
|
-
domain: string
|
|
7
|
-
subdomains?: string[]
|
|
8
|
-
validationMethod?: 'DNS' | 'EMAIL'
|
|
9
|
-
}
|
|
10
|
-
waf?: {
|
|
11
|
-
enabled: boolean
|
|
12
|
-
rules?: string[]
|
|
13
|
-
rateLimit?: number
|
|
14
|
-
scope?: 'REGIONAL' | 'CLOUDFRONT'
|
|
15
|
-
}
|
|
16
|
-
securityGroups?: Record<string, {
|
|
17
|
-
ingress?: Array<{
|
|
18
|
-
port: number
|
|
19
|
-
protocol: string
|
|
20
|
-
cidr?: string
|
|
21
|
-
source?: string
|
|
22
|
-
}>
|
|
23
|
-
egress?: Array<{
|
|
24
|
-
port: number
|
|
25
|
-
protocol: string
|
|
26
|
-
cidr?: string
|
|
27
|
-
}>
|
|
28
|
-
}>
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Add security resources (ACM certificates, WAF, security groups) to CloudFormation template
|
|
33
|
-
*/
|
|
34
|
-
export function addSecurityResources(
|
|
35
|
-
builder: CloudFormationBuilder,
|
|
36
|
-
config: SecurityConfig,
|
|
37
|
-
): void {
|
|
38
|
-
// ACM Certificate
|
|
39
|
-
if (config.certificate) {
|
|
40
|
-
addCertificate(builder, config.certificate)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// WAF Web ACL
|
|
44
|
-
if (config.waf?.enabled) {
|
|
45
|
-
addWAF(builder, config.waf)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Additional Security Groups
|
|
49
|
-
if (config.securityGroups) {
|
|
50
|
-
for (const [name, sgConfig] of Object.entries(config.securityGroups)) {
|
|
51
|
-
addSecurityGroup(builder, name, sgConfig)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Add ACM SSL/TLS Certificate
|
|
58
|
-
*/
|
|
59
|
-
function addCertificate(
|
|
60
|
-
builder: CloudFormationBuilder,
|
|
61
|
-
config: SecurityConfig['certificate'],
|
|
62
|
-
): void {
|
|
63
|
-
if (!config) return
|
|
64
|
-
|
|
65
|
-
const domains = [config.domain]
|
|
66
|
-
if (config.subdomains) {
|
|
67
|
-
domains.push(...config.subdomains)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
builder.addResource('Certificate', 'AWS::CertificateManager::Certificate', {
|
|
71
|
-
DomainName: config.domain,
|
|
72
|
-
SubjectAlternativeNames: config.subdomains,
|
|
73
|
-
ValidationMethod: config.validationMethod || 'DNS',
|
|
74
|
-
DomainValidationOptions: domains.map(domain => ({
|
|
75
|
-
DomainName: domain,
|
|
76
|
-
HostedZoneId: Fn.ref('HostedZone'),
|
|
77
|
-
})),
|
|
78
|
-
Tags: [
|
|
79
|
-
{ Key: 'Name', Value: Fn.sub(`\${AWS::StackName}-certificate`) },
|
|
80
|
-
],
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
// Output
|
|
84
|
-
builder.addOutputs({
|
|
85
|
-
CertificateArn: {
|
|
86
|
-
Description: 'ACM Certificate ARN',
|
|
87
|
-
Value: Fn.ref('Certificate'),
|
|
88
|
-
Export: {
|
|
89
|
-
Name: Fn.sub('${AWS::StackName}-certificate-arn'),
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Add AWS WAF Web ACL
|
|
97
|
-
*/
|
|
98
|
-
function addWAF(
|
|
99
|
-
builder: CloudFormationBuilder,
|
|
100
|
-
config: SecurityConfig['waf'],
|
|
101
|
-
): void {
|
|
102
|
-
if (!config) return
|
|
103
|
-
|
|
104
|
-
const rules: any[] = []
|
|
105
|
-
const ruleNames = config.rules || ['rateLimit', 'sqlInjection', 'xss']
|
|
106
|
-
|
|
107
|
-
// Rate limiting rule
|
|
108
|
-
if (ruleNames.includes('rateLimit')) {
|
|
109
|
-
rules.push({
|
|
110
|
-
Name: 'RateLimitRule',
|
|
111
|
-
Priority: 1,
|
|
112
|
-
Statement: {
|
|
113
|
-
RateBasedStatement: {
|
|
114
|
-
Limit: config.rateLimit || 2000,
|
|
115
|
-
AggregateKeyType: 'IP',
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
Action: {
|
|
119
|
-
Block: {},
|
|
120
|
-
},
|
|
121
|
-
VisibilityConfig: {
|
|
122
|
-
SampledRequestsEnabled: true,
|
|
123
|
-
CloudWatchMetricsEnabled: true,
|
|
124
|
-
MetricName: 'RateLimitRule',
|
|
125
|
-
},
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// AWS Managed Rules
|
|
130
|
-
let priority = rules.length + 1
|
|
131
|
-
|
|
132
|
-
if (ruleNames.includes('sqlInjection')) {
|
|
133
|
-
rules.push({
|
|
134
|
-
Name: 'AWSManagedRulesSQLi',
|
|
135
|
-
Priority: priority++,
|
|
136
|
-
Statement: {
|
|
137
|
-
ManagedRuleGroupStatement: {
|
|
138
|
-
VendorName: 'AWS',
|
|
139
|
-
Name: 'AWSManagedRulesSQLiRuleSet',
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
OverrideAction: {
|
|
143
|
-
None: {},
|
|
144
|
-
},
|
|
145
|
-
VisibilityConfig: {
|
|
146
|
-
SampledRequestsEnabled: true,
|
|
147
|
-
CloudWatchMetricsEnabled: true,
|
|
148
|
-
MetricName: 'AWSManagedRulesSQLi',
|
|
149
|
-
},
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (ruleNames.includes('xss')) {
|
|
154
|
-
rules.push({
|
|
155
|
-
Name: 'AWSManagedRulesXSS',
|
|
156
|
-
Priority: priority++,
|
|
157
|
-
Statement: {
|
|
158
|
-
ManagedRuleGroupStatement: {
|
|
159
|
-
VendorName: 'AWS',
|
|
160
|
-
Name: 'AWSManagedRulesKnownBadInputsRuleSet',
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
OverrideAction: {
|
|
164
|
-
None: {},
|
|
165
|
-
},
|
|
166
|
-
VisibilityConfig: {
|
|
167
|
-
SampledRequestsEnabled: true,
|
|
168
|
-
CloudWatchMetricsEnabled: true,
|
|
169
|
-
MetricName: 'AWSManagedRulesXSS',
|
|
170
|
-
},
|
|
171
|
-
})
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (ruleNames.includes('knownBadInputs')) {
|
|
175
|
-
rules.push({
|
|
176
|
-
Name: 'AWSManagedRulesKnownBadInputs',
|
|
177
|
-
Priority: priority++,
|
|
178
|
-
Statement: {
|
|
179
|
-
ManagedRuleGroupStatement: {
|
|
180
|
-
VendorName: 'AWS',
|
|
181
|
-
Name: 'AWSManagedRulesKnownBadInputsRuleSet',
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
OverrideAction: {
|
|
185
|
-
None: {},
|
|
186
|
-
},
|
|
187
|
-
VisibilityConfig: {
|
|
188
|
-
SampledRequestsEnabled: true,
|
|
189
|
-
CloudWatchMetricsEnabled: true,
|
|
190
|
-
MetricName: 'AWSManagedRulesKnownBadInputs',
|
|
191
|
-
},
|
|
192
|
-
})
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (ruleNames.includes('coreRuleSet')) {
|
|
196
|
-
rules.push({
|
|
197
|
-
Name: 'AWSManagedRulesCoreRuleSet',
|
|
198
|
-
Priority: priority++,
|
|
199
|
-
Statement: {
|
|
200
|
-
ManagedRuleGroupStatement: {
|
|
201
|
-
VendorName: 'AWS',
|
|
202
|
-
Name: 'AWSManagedRulesCommonRuleSet',
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
OverrideAction: {
|
|
206
|
-
None: {},
|
|
207
|
-
},
|
|
208
|
-
VisibilityConfig: {
|
|
209
|
-
SampledRequestsEnabled: true,
|
|
210
|
-
CloudWatchMetricsEnabled: true,
|
|
211
|
-
MetricName: 'AWSManagedRulesCoreRuleSet',
|
|
212
|
-
},
|
|
213
|
-
})
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (ruleNames.includes('linuxRuleSet')) {
|
|
217
|
-
rules.push({
|
|
218
|
-
Name: 'AWSManagedRulesLinuxRuleSet',
|
|
219
|
-
Priority: priority++,
|
|
220
|
-
Statement: {
|
|
221
|
-
ManagedRuleGroupStatement: {
|
|
222
|
-
VendorName: 'AWS',
|
|
223
|
-
Name: 'AWSManagedRulesLinuxRuleSet',
|
|
224
|
-
},
|
|
225
|
-
},
|
|
226
|
-
OverrideAction: {
|
|
227
|
-
None: {},
|
|
228
|
-
},
|
|
229
|
-
VisibilityConfig: {
|
|
230
|
-
SampledRequestsEnabled: true,
|
|
231
|
-
CloudWatchMetricsEnabled: true,
|
|
232
|
-
MetricName: 'AWSManagedRulesLinuxRuleSet',
|
|
233
|
-
},
|
|
234
|
-
})
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (ruleNames.includes('apiProtection')) {
|
|
238
|
-
rules.push({
|
|
239
|
-
Name: 'AWSManagedRulesAPIProtection',
|
|
240
|
-
Priority: priority++,
|
|
241
|
-
Statement: {
|
|
242
|
-
ManagedRuleGroupStatement: {
|
|
243
|
-
VendorName: 'AWS',
|
|
244
|
-
Name: 'AWSManagedRulesAmazonIpReputationList',
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
OverrideAction: {
|
|
248
|
-
None: {},
|
|
249
|
-
},
|
|
250
|
-
VisibilityConfig: {
|
|
251
|
-
SampledRequestsEnabled: true,
|
|
252
|
-
CloudWatchMetricsEnabled: true,
|
|
253
|
-
MetricName: 'AWSManagedRulesAPIProtection',
|
|
254
|
-
},
|
|
255
|
-
})
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (ruleNames.includes('geoBlock')) {
|
|
259
|
-
// Example: Block traffic from certain countries
|
|
260
|
-
rules.push({
|
|
261
|
-
Name: 'GeoBlockRule',
|
|
262
|
-
Priority: priority++,
|
|
263
|
-
Statement: {
|
|
264
|
-
GeoMatchStatement: {
|
|
265
|
-
CountryCodes: ['CN', 'RU'], // Example countries to block
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
Action: {
|
|
269
|
-
Block: {},
|
|
270
|
-
},
|
|
271
|
-
VisibilityConfig: {
|
|
272
|
-
SampledRequestsEnabled: true,
|
|
273
|
-
CloudWatchMetricsEnabled: true,
|
|
274
|
-
MetricName: 'GeoBlockRule',
|
|
275
|
-
},
|
|
276
|
-
})
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (ruleNames.includes('connectionLimit')) {
|
|
280
|
-
rules.push({
|
|
281
|
-
Name: 'ConnectionLimitRule',
|
|
282
|
-
Priority: priority++,
|
|
283
|
-
Statement: {
|
|
284
|
-
RateBasedStatement: {
|
|
285
|
-
Limit: 100,
|
|
286
|
-
AggregateKeyType: 'IP',
|
|
287
|
-
},
|
|
288
|
-
},
|
|
289
|
-
Action: {
|
|
290
|
-
Block: {},
|
|
291
|
-
},
|
|
292
|
-
VisibilityConfig: {
|
|
293
|
-
SampledRequestsEnabled: true,
|
|
294
|
-
CloudWatchMetricsEnabled: true,
|
|
295
|
-
MetricName: 'ConnectionLimitRule',
|
|
296
|
-
},
|
|
297
|
-
})
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Web ACL
|
|
301
|
-
builder.addResource('WebACL', 'AWS::WAFv2::WebACL', {
|
|
302
|
-
Name: Fn.sub('${AWS::StackName}-waf'),
|
|
303
|
-
Scope: config.scope || 'REGIONAL',
|
|
304
|
-
DefaultAction: {
|
|
305
|
-
Allow: {},
|
|
306
|
-
},
|
|
307
|
-
Rules: rules,
|
|
308
|
-
VisibilityConfig: {
|
|
309
|
-
SampledRequestsEnabled: true,
|
|
310
|
-
CloudWatchMetricsEnabled: true,
|
|
311
|
-
MetricName: Fn.sub('${AWS::StackName}-waf'),
|
|
312
|
-
},
|
|
313
|
-
Tags: [
|
|
314
|
-
{ Key: 'Name', Value: Fn.sub('${AWS::StackName}-waf') },
|
|
315
|
-
],
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
// Associate WAF with ALB (if exists)
|
|
319
|
-
if (builder.hasResource('LoadBalancer')) {
|
|
320
|
-
builder.addResource('WebACLAssociation', 'AWS::WAFv2::WebACLAssociation', {
|
|
321
|
-
ResourceArn: Fn.ref('LoadBalancer'),
|
|
322
|
-
WebACLArn: Fn.getAtt('WebACL', 'Arn'),
|
|
323
|
-
}, {
|
|
324
|
-
dependsOn: ['WebACL', 'LoadBalancer'],
|
|
325
|
-
})
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// Output
|
|
329
|
-
builder.addOutputs({
|
|
330
|
-
WebACLId: {
|
|
331
|
-
Description: 'WAF Web ACL ID',
|
|
332
|
-
Value: Fn.ref('WebACL'),
|
|
333
|
-
Export: {
|
|
334
|
-
Name: Fn.sub('${AWS::StackName}-waf-id'),
|
|
335
|
-
},
|
|
336
|
-
},
|
|
337
|
-
WebACLArn: {
|
|
338
|
-
Description: 'WAF Web ACL ARN',
|
|
339
|
-
Value: Fn.getAtt('WebACL', 'Arn'),
|
|
340
|
-
Export: {
|
|
341
|
-
Name: Fn.sub('${AWS::StackName}-waf-arn'),
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
})
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Add Security Group
|
|
349
|
-
*/
|
|
350
|
-
function addSecurityGroup(
|
|
351
|
-
builder: CloudFormationBuilder,
|
|
352
|
-
name: string,
|
|
353
|
-
config: NonNullable<SecurityConfig['securityGroups']>[string] | undefined,
|
|
354
|
-
): void {
|
|
355
|
-
if (!config) return
|
|
356
|
-
|
|
357
|
-
const logicalId = builder.toLogicalId(`${name}-security-group`)
|
|
358
|
-
|
|
359
|
-
const ingressRules = config.ingress?.map((rule: NonNullable<NonNullable<SecurityConfig['securityGroups']>[string]['ingress']>[number]) => ({
|
|
360
|
-
IpProtocol: rule.protocol,
|
|
361
|
-
FromPort: rule.port,
|
|
362
|
-
ToPort: rule.port,
|
|
363
|
-
CidrIp: rule.cidr,
|
|
364
|
-
SourceSecurityGroupId: rule.source ? Fn.ref(rule.source) : undefined,
|
|
365
|
-
})) || []
|
|
366
|
-
|
|
367
|
-
const egressRules = config.egress?.map((rule: NonNullable<NonNullable<SecurityConfig['securityGroups']>[string]['egress']>[number]) => ({
|
|
368
|
-
IpProtocol: rule.protocol,
|
|
369
|
-
FromPort: rule.port,
|
|
370
|
-
ToPort: rule.port,
|
|
371
|
-
CidrIp: rule.cidr || '0.0.0.0/0',
|
|
372
|
-
})) || [{
|
|
373
|
-
IpProtocol: '-1',
|
|
374
|
-
CidrIp: '0.0.0.0/0',
|
|
375
|
-
}]
|
|
376
|
-
|
|
377
|
-
builder.addResource(logicalId, 'AWS::EC2::SecurityGroup', {
|
|
378
|
-
GroupDescription: `Security group for ${name}`,
|
|
379
|
-
VpcId: Fn.ref('VPC'),
|
|
380
|
-
SecurityGroupIngress: ingressRules,
|
|
381
|
-
SecurityGroupEgress: egressRules,
|
|
382
|
-
Tags: [
|
|
383
|
-
{ Key: 'Name', Value: Fn.sub(`\${AWS::StackName}-${name}-sg`) },
|
|
384
|
-
],
|
|
385
|
-
}, {
|
|
386
|
-
dependsOn: 'VPC',
|
|
387
|
-
})
|
|
388
|
-
|
|
389
|
-
// Output
|
|
390
|
-
builder.addOutputs({
|
|
391
|
-
[`${logicalId}Id`]: {
|
|
392
|
-
Description: `${name} security group ID`,
|
|
393
|
-
Value: Fn.ref(logicalId),
|
|
394
|
-
Export: {
|
|
395
|
-
Name: Fn.sub(`\${AWS::StackName}-${name}-sg-id`),
|
|
396
|
-
},
|
|
397
|
-
},
|
|
398
|
-
})
|
|
399
|
-
}
|
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import type { CloudFormationBuilder } from '../builder'
|
|
2
|
-
import { Arn, Fn } from '../types'
|
|
3
|
-
|
|
4
|
-
export interface StorageConfig {
|
|
5
|
-
[bucketName: string]: {
|
|
6
|
-
public?: boolean
|
|
7
|
-
versioning?: boolean
|
|
8
|
-
website?: boolean
|
|
9
|
-
encryption?: boolean
|
|
10
|
-
intelligentTiering?: boolean
|
|
11
|
-
cors?: Array<{
|
|
12
|
-
allowedOrigins: string[]
|
|
13
|
-
allowedMethods: string[]
|
|
14
|
-
allowedHeaders?: string[]
|
|
15
|
-
maxAge?: number
|
|
16
|
-
}>
|
|
17
|
-
lifecycleRules?: Array<{
|
|
18
|
-
id: string
|
|
19
|
-
enabled: boolean
|
|
20
|
-
expirationDays?: number
|
|
21
|
-
transitions?: Array<{
|
|
22
|
-
days: number
|
|
23
|
-
storageClass: 'STANDARD_IA' | 'ONEZONE_IA' | 'INTELLIGENT_TIERING' | 'GLACIER' | 'DEEP_ARCHIVE'
|
|
24
|
-
}>
|
|
25
|
-
}>
|
|
26
|
-
type?: 'efs'
|
|
27
|
-
performanceMode?: 'generalPurpose' | 'maxIO'
|
|
28
|
-
throughputMode?: 'bursting' | 'provisioned'
|
|
29
|
-
lifecyclePolicy?: {
|
|
30
|
-
transitionToIA?: number
|
|
31
|
-
transitionToPrimaryStorageClass?: number
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Add S3 and EFS storage resources to CloudFormation template
|
|
38
|
-
*/
|
|
39
|
-
export function addStorageResources(
|
|
40
|
-
builder: CloudFormationBuilder,
|
|
41
|
-
config: StorageConfig,
|
|
42
|
-
): void {
|
|
43
|
-
for (const [bucketName, bucketConfig] of Object.entries(config)) {
|
|
44
|
-
// Check if this is an EFS configuration
|
|
45
|
-
if (bucketConfig.type === 'efs') {
|
|
46
|
-
addEFSResource(builder, bucketName, bucketConfig)
|
|
47
|
-
continue
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Otherwise, create S3 bucket
|
|
51
|
-
addS3Bucket(builder, bucketName, bucketConfig)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Add S3 bucket resource
|
|
57
|
-
*/
|
|
58
|
-
function addS3Bucket(
|
|
59
|
-
builder: CloudFormationBuilder,
|
|
60
|
-
bucketName: string,
|
|
61
|
-
config: StorageConfig[string],
|
|
62
|
-
): void {
|
|
63
|
-
const logicalId = builder.toLogicalId(`${bucketName}-bucket`)
|
|
64
|
-
const properties: Record<string, any> = {
|
|
65
|
-
BucketName: Fn.sub(`\${AWS::StackName}-${bucketName}`),
|
|
66
|
-
Tags: [
|
|
67
|
-
{ Key: 'Name', Value: Fn.sub(`\${AWS::StackName}-${bucketName}`) },
|
|
68
|
-
],
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Versioning
|
|
72
|
-
if (config.versioning) {
|
|
73
|
-
properties.VersioningConfiguration = {
|
|
74
|
-
Status: 'Enabled',
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Encryption
|
|
79
|
-
if (config.encryption) {
|
|
80
|
-
properties.BucketEncryption = {
|
|
81
|
-
ServerSideEncryptionConfiguration: [{
|
|
82
|
-
ServerSideEncryptionByDefault: {
|
|
83
|
-
SSEAlgorithm: 'AES256',
|
|
84
|
-
},
|
|
85
|
-
}],
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Public access
|
|
90
|
-
if (!config.public) {
|
|
91
|
-
properties.PublicAccessBlockConfiguration = {
|
|
92
|
-
BlockPublicAcls: true,
|
|
93
|
-
BlockPublicPolicy: true,
|
|
94
|
-
IgnorePublicAcls: true,
|
|
95
|
-
RestrictPublicBuckets: true,
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Website configuration
|
|
100
|
-
if (config.website) {
|
|
101
|
-
properties.WebsiteConfiguration = {
|
|
102
|
-
IndexDocument: 'index.html',
|
|
103
|
-
ErrorDocument: 'index.html', // For SPA routing
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// CORS configuration
|
|
108
|
-
if (config.cors && config.cors.length > 0) {
|
|
109
|
-
properties.CorsConfiguration = {
|
|
110
|
-
CorsRules: config.cors.map(rule => ({
|
|
111
|
-
AllowedOrigins: rule.allowedOrigins,
|
|
112
|
-
AllowedMethods: rule.allowedMethods,
|
|
113
|
-
AllowedHeaders: rule.allowedHeaders || ['*'],
|
|
114
|
-
MaxAge: rule.maxAge || 3600,
|
|
115
|
-
})),
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Lifecycle rules
|
|
120
|
-
if (config.lifecycleRules && config.lifecycleRules.length > 0) {
|
|
121
|
-
properties.LifecycleConfiguration = {
|
|
122
|
-
Rules: config.lifecycleRules.map(rule => ({
|
|
123
|
-
Id: rule.id,
|
|
124
|
-
Status: rule.enabled ? 'Enabled' : 'Disabled',
|
|
125
|
-
ExpirationInDays: rule.expirationDays,
|
|
126
|
-
Transitions: rule.transitions?.map(t => ({
|
|
127
|
-
TransitionInDays: t.days,
|
|
128
|
-
StorageClass: t.storageClass,
|
|
129
|
-
})),
|
|
130
|
-
})),
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Intelligent tiering
|
|
135
|
-
if (config.intelligentTiering) {
|
|
136
|
-
properties.IntelligentTieringConfigurations = [{
|
|
137
|
-
Id: 'EntireBucket',
|
|
138
|
-
Status: 'Enabled',
|
|
139
|
-
Tierings: [
|
|
140
|
-
{
|
|
141
|
-
AccessTier: 'ARCHIVE_ACCESS',
|
|
142
|
-
Days: 90,
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
AccessTier: 'DEEP_ARCHIVE_ACCESS',
|
|
146
|
-
Days: 180,
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
}]
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
builder.addResource(logicalId, 'AWS::S3::Bucket', properties, {
|
|
153
|
-
deletionPolicy: config.versioning ? 'Retain' : 'Delete',
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
// Bucket policy for public access if needed
|
|
157
|
-
if (config.public) {
|
|
158
|
-
builder.addResource(`${logicalId}Policy`, 'AWS::S3::BucketPolicy', {
|
|
159
|
-
Bucket: Fn.ref(logicalId),
|
|
160
|
-
PolicyDocument: {
|
|
161
|
-
Version: '2012-10-17',
|
|
162
|
-
Statement: [{
|
|
163
|
-
Sid: 'PublicReadGetObject',
|
|
164
|
-
Effect: 'Allow',
|
|
165
|
-
Principal: '*',
|
|
166
|
-
Action: 's3:GetObject',
|
|
167
|
-
Resource: Fn.join('', [Arn.s3Bucket(Fn.ref(logicalId) as any), '/*']),
|
|
168
|
-
}],
|
|
169
|
-
},
|
|
170
|
-
}, {
|
|
171
|
-
dependsOn: logicalId,
|
|
172
|
-
})
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Output bucket name and ARN
|
|
176
|
-
builder.addOutputs({
|
|
177
|
-
[`${logicalId}Name`]: {
|
|
178
|
-
Description: `${bucketName} bucket name`,
|
|
179
|
-
Value: Fn.ref(logicalId),
|
|
180
|
-
Export: {
|
|
181
|
-
Name: Fn.sub(`\${AWS::StackName}-${bucketName}-bucket`),
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
[`${logicalId}Arn`]: {
|
|
185
|
-
Description: `${bucketName} bucket ARN`,
|
|
186
|
-
Value: Fn.getAtt(logicalId, 'Arn'),
|
|
187
|
-
Export: {
|
|
188
|
-
Name: Fn.sub(`\${AWS::StackName}-${bucketName}-bucket-arn`),
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
if (config.website) {
|
|
194
|
-
builder.addOutputs({
|
|
195
|
-
[`${logicalId}WebsiteURL`]: {
|
|
196
|
-
Description: `${bucketName} website URL`,
|
|
197
|
-
Value: Fn.getAtt(logicalId, 'WebsiteURL'),
|
|
198
|
-
},
|
|
199
|
-
})
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Add EFS file system resource
|
|
205
|
-
*/
|
|
206
|
-
function addEFSResource(
|
|
207
|
-
builder: CloudFormationBuilder,
|
|
208
|
-
name: string,
|
|
209
|
-
config: StorageConfig[string],
|
|
210
|
-
): void {
|
|
211
|
-
const logicalId = builder.toLogicalId(`${name}-efs`)
|
|
212
|
-
|
|
213
|
-
// EFS File System
|
|
214
|
-
const properties: Record<string, any> = {
|
|
215
|
-
Encrypted: config.encryption !== false,
|
|
216
|
-
PerformanceMode: config.performanceMode || 'generalPurpose',
|
|
217
|
-
ThroughputMode: config.throughputMode || 'bursting',
|
|
218
|
-
FileSystemTags: [
|
|
219
|
-
{ Key: 'Name', Value: Fn.sub(`\${AWS::StackName}-${name}`) },
|
|
220
|
-
],
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Lifecycle policy
|
|
224
|
-
if (config.lifecyclePolicy) {
|
|
225
|
-
properties.LifecyclePolicies = []
|
|
226
|
-
|
|
227
|
-
if (config.lifecyclePolicy.transitionToIA) {
|
|
228
|
-
properties.LifecyclePolicies.push({
|
|
229
|
-
TransitionToIA: `AFTER_${config.lifecyclePolicy.transitionToIA}_DAYS`,
|
|
230
|
-
})
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (config.lifecyclePolicy.transitionToPrimaryStorageClass) {
|
|
234
|
-
properties.LifecyclePolicies.push({
|
|
235
|
-
TransitionToPrimaryStorageClass: 'AFTER_1_ACCESS',
|
|
236
|
-
})
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
builder.addResource(logicalId, 'AWS::EFS::FileSystem', properties, {
|
|
241
|
-
deletionPolicy: 'Retain',
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
// EFS Mount Targets (one per AZ/subnet)
|
|
245
|
-
// Note: Assumes VPC and subnets are already created
|
|
246
|
-
// In a real implementation, you'd get the subnet IDs from the VPC configuration
|
|
247
|
-
const availabilityZones = 2 // Should come from network config
|
|
248
|
-
for (let i = 0; i < availabilityZones; i++) {
|
|
249
|
-
builder.addResource(`${logicalId}MountTarget${i + 1}`, 'AWS::EFS::MountTarget', {
|
|
250
|
-
FileSystemId: Fn.ref(logicalId),
|
|
251
|
-
SubnetId: Fn.ref(`PrivateSubnet${i + 1}`),
|
|
252
|
-
SecurityGroups: [Fn.ref('EFSSecurityGroup')],
|
|
253
|
-
}, {
|
|
254
|
-
dependsOn: [logicalId, `PrivateSubnet${i + 1}`],
|
|
255
|
-
})
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// Security group for EFS
|
|
259
|
-
builder.addResource('EFSSecurityGroup', 'AWS::EC2::SecurityGroup', {
|
|
260
|
-
GroupDescription: 'Security group for EFS mount targets',
|
|
261
|
-
VpcId: Fn.ref('VPC'),
|
|
262
|
-
SecurityGroupIngress: [{
|
|
263
|
-
IpProtocol: 'tcp',
|
|
264
|
-
FromPort: 2049,
|
|
265
|
-
ToPort: 2049,
|
|
266
|
-
SourceSecurityGroupId: Fn.ref('AppSecurityGroup'), // Assumes app security group exists
|
|
267
|
-
}],
|
|
268
|
-
Tags: [
|
|
269
|
-
{ Key: 'Name', Value: Fn.sub('${AWS::StackName}-efs-sg') },
|
|
270
|
-
],
|
|
271
|
-
}, {
|
|
272
|
-
dependsOn: 'VPC',
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
// Output EFS ID
|
|
276
|
-
builder.addOutputs({
|
|
277
|
-
[`${logicalId}Id`]: {
|
|
278
|
-
Description: `${name} EFS file system ID`,
|
|
279
|
-
Value: Fn.ref(logicalId),
|
|
280
|
-
Export: {
|
|
281
|
-
Name: Fn.sub(`\${AWS::StackName}-${name}-efs`),
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
})
|
|
285
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// CloudFormation template builder
|
|
2
|
-
export {
|
|
3
|
-
CloudFormationBuilder,
|
|
4
|
-
buildCloudFormationTemplate,
|
|
5
|
-
} from './builder'
|
|
6
|
-
|
|
7
|
-
// CloudFormation types
|
|
8
|
-
export type {
|
|
9
|
-
CloudFormationTemplate,
|
|
10
|
-
CloudFormationResource,
|
|
11
|
-
CloudFormationParameter,
|
|
12
|
-
CloudFormationOutput,
|
|
13
|
-
CloudFormationCondition,
|
|
14
|
-
CloudFormationIntrinsicFunction,
|
|
15
|
-
} from './types'
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
Fn,
|
|
19
|
-
Arn,
|
|
20
|
-
AWS_PSEUDO_PARAMETERS,
|
|
21
|
-
} from './types'
|
|
22
|
-
|
|
23
|
-
// Resource builders
|
|
24
|
-
export { addNetworkResources } from './builders/network'
|
|
25
|
-
export { addStorageResources } from './builders/storage'
|
|
26
|
-
export { addComputeResources } from './builders/compute'
|
|
27
|
-
export { addDatabaseResources } from './builders/database'
|
|
28
|
-
export { addFunctionResources } from './builders/functions'
|
|
29
|
-
export { addQueueResources } from './builders/queue'
|
|
30
|
-
export type { QueueConfig } from './builders/queue'
|