@fjall/components-infrastructure 0.95.0 → 0.96.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/app.d.ts +25 -109
- package/dist/lib/app.js +37 -136
- package/dist/lib/patterns/aws/account.js +5 -4
- package/dist/lib/patterns/aws/computeEcs.d.ts +8 -397
- package/dist/lib/patterns/aws/computeEcs.js +13 -9
- package/dist/lib/patterns/aws/computeEcsTypes.d.ts +386 -0
- package/dist/lib/patterns/aws/computeEcsTypes.js +2 -0
- package/dist/lib/patterns/aws/domain.js +4 -5
- package/dist/lib/patterns/aws/index.d.ts +2 -0
- package/dist/lib/patterns/aws/index.js +2 -0
- package/dist/lib/patterns/aws/interfaces/compute.d.ts +6 -0
- package/dist/lib/patterns/aws/interfaces/connector.d.ts +1 -1
- package/dist/lib/patterns/aws/interfaces/connector.js +1 -1
- package/dist/lib/patterns/aws/interfaces/index.d.ts +2 -1
- package/dist/lib/patterns/aws/interfaces/index.js +1 -1
- package/dist/lib/patterns/aws/interfaces/vpcPeer.d.ts +7 -0
- package/dist/lib/patterns/aws/interfaces/vpcPeer.js +1 -0
- package/dist/lib/patterns/aws/organisation.js +2 -1
- package/dist/lib/patterns/aws/vpcPeer.d.ts +34 -0
- package/dist/lib/patterns/aws/vpcPeer.js +36 -0
- package/dist/lib/patterns/aws/vpcPeerAccepter.d.ts +29 -0
- package/dist/lib/patterns/aws/vpcPeerAccepter.js +196 -0
- package/dist/lib/resources/aws/analytics/clickhouse.js +10 -1
- package/dist/lib/resources/aws/analytics/clickhouseAlarms.d.ts +34 -0
- package/dist/lib/resources/aws/analytics/clickhouseAlarms.js +89 -0
- package/dist/lib/resources/aws/analytics/clickhouseConstants.d.ts +1 -1
- package/dist/lib/resources/aws/analytics/clickhouseConstants.js +3 -1
- package/dist/lib/resources/aws/analytics/clickhouseTypes.d.ts +6 -0
- package/dist/lib/resources/aws/analytics/clickhouseUserData.d.ts +1 -0
- package/dist/lib/resources/aws/analytics/clickhouseUserData.js +3 -2
- package/dist/lib/resources/aws/analytics/index.d.ts +2 -0
- package/dist/lib/resources/aws/analytics/index.js +1 -0
- package/dist/lib/resources/aws/compute/ecsRemoteConnections.d.ts +38 -0
- package/dist/lib/resources/aws/compute/ecsRemoteConnections.js +80 -0
- package/dist/lib/resources/aws/compute/ecsTaskDefinition.js +8 -0
- package/dist/lib/resources/aws/compute/ecsTypes.d.ts +7 -0
- package/dist/lib/resources/aws/iam/delegationRole.js +11 -4
- package/dist/lib/resources/aws/networking/crossAccountDelegationRecord.js +2 -1
- package/dist/lib/resources/aws/networking/crossAccountReturnRoutes.d.ts +40 -0
- package/dist/lib/resources/aws/networking/crossAccountReturnRoutes.js +154 -0
- package/dist/lib/resources/aws/networking/dnsRecord/dnsRecordBase.js +2 -1
- package/dist/lib/resources/aws/networking/domainCertificate.js +2 -1
- package/dist/lib/resources/aws/networking/hostedZone.js +2 -1
- package/dist/lib/resources/aws/networking/index.d.ts +3 -0
- package/dist/lib/resources/aws/networking/index.js +3 -0
- package/dist/lib/resources/aws/networking/vpc.js +6 -2
- package/dist/lib/resources/aws/networking/vpcPeeringAccepterRole.d.ts +18 -0
- package/dist/lib/resources/aws/networking/vpcPeeringAccepterRole.js +61 -0
- package/dist/lib/resources/aws/networking/vpcPeeringConnection.d.ts +49 -0
- package/dist/lib/resources/aws/networking/vpcPeeringConnection.js +88 -0
- package/dist/lib/utils/bastionFactory.d.ts +10 -0
- package/dist/lib/utils/bastionFactory.js +29 -0
- package/dist/lib/utils/capitaliseString.d.ts +1 -1
- package/dist/lib/utils/capitaliseString.js +1 -1
- package/dist/lib/utils/cdkContext.d.ts +8 -0
- package/dist/lib/utils/cdkContext.js +11 -0
- package/dist/lib/utils/connections.d.ts +7 -1
- package/dist/lib/utils/connections.js +15 -0
- package/dist/lib/utils/connector.d.ts +18 -2
- package/dist/lib/utils/connector.js +6 -1
- package/dist/lib/utils/costAllocationTags.d.ts +6 -0
- package/dist/lib/utils/costAllocationTags.js +6 -0
- package/dist/lib/utils/index.d.ts +3 -0
- package/dist/lib/utils/index.js +3 -0
- package/dist/lib/utils/vpcPeerInterface.d.ts +22 -0
- package/dist/lib/utils/vpcPeerInterface.js +1 -0
- package/package.json +4 -3
|
@@ -1,405 +1,15 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type
|
|
3
|
-
import { type
|
|
4
|
-
import { type PolicyDocument, type IManagedPolicy, type IGrantable, Grant } from "aws-cdk-lib/aws-iam";
|
|
1
|
+
import { type ICluster, type IBaseService } from "aws-cdk-lib/aws-ecs";
|
|
2
|
+
import { type Connections, type ISecurityGroup } from "aws-cdk-lib/aws-ec2";
|
|
3
|
+
import { type IGrantable, Grant } from "aws-cdk-lib/aws-iam";
|
|
5
4
|
import { type IApplicationLoadBalancer, type ApplicationListener } from "aws-cdk-lib/aws-elasticloadbalancingv2";
|
|
6
5
|
import { Construct } from "constructs";
|
|
7
|
-
import type { ITopic } from "aws-cdk-lib/aws-sns";
|
|
8
6
|
import { type IEcsCompute } from "./interfaces/compute.js";
|
|
9
|
-
import { type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { type
|
|
13
|
-
export { ScalingType };
|
|
14
|
-
export type { EcsCapacityProvider, Ec2CapacityConfig };
|
|
15
|
-
/**
|
|
16
|
-
* Configuration for ECS capacity providers.
|
|
17
|
-
*/
|
|
18
|
-
export interface EcsCapacityProviderConfig {
|
|
19
|
-
/** Whether this uses Spot pricing */
|
|
20
|
-
usesSpot: boolean;
|
|
21
|
-
/** Whether this runs on EC2 instances (vs serverless Fargate) */
|
|
22
|
-
usesEc2Instances: boolean;
|
|
23
|
-
}
|
|
7
|
+
import EcsCluster, { type EcsClusterProps } from "../../resources/aws/compute/ecs.js";
|
|
8
|
+
export { ScalingType } from "./computeEcsTypes.js";
|
|
9
|
+
export type { EcsCapacityProvider, Ec2CapacityConfig, RemoteConnectionSpec, EcsCapacityProviderConfig, EcsContainerConfig, EcsScalingConfig, EcsClusterConfig, EcsRoutingConfig, EcsServiceConfig, EcsComputeProps } from "./computeEcsTypes.js";
|
|
10
|
+
import { ScalingType, type EcsCapacityProviderConfig, type EcsCapacityProvider, type EcsScalingConfig, type EcsServiceConfig, type EcsComputeProps } from "./computeEcsTypes.js";
|
|
24
11
|
export declare const ECS_CAPACITY_PROVIDER_CONFIG: Record<EcsCapacityProvider, EcsCapacityProviderConfig>;
|
|
25
12
|
export declare function getEcsCapacityProviderConfig(provider: EcsCapacityProvider): EcsCapacityProviderConfig;
|
|
26
|
-
/**
|
|
27
|
-
* Configuration for a container in an ECS task.
|
|
28
|
-
*
|
|
29
|
-
* For single-container services, `name` is optional and defaults to `${serviceName}Container`.
|
|
30
|
-
* For multi-container tasks, the first container with a `port` is the **primary container**
|
|
31
|
-
* that receives load balancer traffic.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* // Single container (name auto-generated)
|
|
35
|
-
* containers: [{ port: 3000 }]
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* // Multi-container with sidecars
|
|
39
|
-
* containers: [
|
|
40
|
-
* { name: "app", port: 3000 }, // Primary - receives ALB traffic
|
|
41
|
-
* { name: "datadog", image: "datadog/agent" } // Sidecar - monitoring
|
|
42
|
-
* ]
|
|
43
|
-
*/
|
|
44
|
-
export interface EcsContainerConfig {
|
|
45
|
-
/** Container name. Optional for single-container services. */
|
|
46
|
-
name?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Container image. Options:
|
|
49
|
-
* - Omit: Uses app's default ECR repository (primary container only)
|
|
50
|
-
* - string: ECR repository name or public image URL
|
|
51
|
-
* - Repository: CDK ECR Repository construct
|
|
52
|
-
*/
|
|
53
|
-
image?: string | Repository;
|
|
54
|
-
/**
|
|
55
|
-
* Port the container listens on.
|
|
56
|
-
* The first container with a port becomes the **primary container**
|
|
57
|
-
* and is registered with the load balancer.
|
|
58
|
-
*/
|
|
59
|
-
port?: number;
|
|
60
|
-
/** Environment variables */
|
|
61
|
-
environment?: Record<string, string>;
|
|
62
|
-
/**
|
|
63
|
-
* Secrets from AWS SSM Parameter Store.
|
|
64
|
-
* Array of secret names that will be fetched from the service's SSM namespace.
|
|
65
|
-
* The namespace path is auto-determined from app/cluster/service names.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* // Secrets at /myapp/api-cluster/users/API_KEY and /myapp/api-cluster/users/DB_PASSWORD
|
|
69
|
-
* secrets: ["API_KEY", "DB_PASSWORD"]
|
|
70
|
-
*/
|
|
71
|
-
secrets?: string[];
|
|
72
|
-
/** Secrets imported from other CDK resources (AWS Secrets Manager) */
|
|
73
|
-
secretsImport?: Record<string, SecretImport>;
|
|
74
|
-
/** Command to run in the container */
|
|
75
|
-
command?: string[];
|
|
76
|
-
/** Entry point for the container */
|
|
77
|
-
entryPoint?: string[];
|
|
78
|
-
/**
|
|
79
|
-
* Whether this container is essential.
|
|
80
|
-
* If an essential container stops, all containers in the task stop.
|
|
81
|
-
* Default: true
|
|
82
|
-
*/
|
|
83
|
-
essential?: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Health check configuration.
|
|
86
|
-
* Default: For primary container with port, uses curl health check.
|
|
87
|
-
*/
|
|
88
|
-
healthCheck?: {
|
|
89
|
-
command: string[];
|
|
90
|
-
interval?: number;
|
|
91
|
-
timeout?: number;
|
|
92
|
-
retries?: number;
|
|
93
|
-
startPeriod?: number;
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* ECS scaling configuration.
|
|
98
|
-
* - Omit: enabled with defaults
|
|
99
|
-
* - `{}`: enabled with defaults
|
|
100
|
-
* - `{ minCapacity: 2, maxCapacity: 10 }`: custom scaling
|
|
101
|
-
* - `false`: explicitly disabled
|
|
102
|
-
*/
|
|
103
|
-
export interface EcsScalingConfig {
|
|
104
|
-
minCapacity?: number;
|
|
105
|
-
maxCapacity?: number;
|
|
106
|
-
scalingType?: ScalingType;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Cluster-level configuration.
|
|
110
|
-
* Controls the shared ALB for all services in this cluster.
|
|
111
|
-
*/
|
|
112
|
-
export interface EcsClusterConfig {
|
|
113
|
-
/**
|
|
114
|
-
* Domain for HTTPS access.
|
|
115
|
-
* - Omit: ALB created with default DNS (*.elb.amazonaws.com)
|
|
116
|
-
* - Specified: Creates ACM certificate + Route53 DNS A record
|
|
117
|
-
*/
|
|
118
|
-
domain?: string;
|
|
119
|
-
/**
|
|
120
|
-
* Load balancer configuration.
|
|
121
|
-
* - Omit or "public": Internet-facing ALB (default)
|
|
122
|
-
* - "internal": VPC-only ALB
|
|
123
|
-
* - false: No ALB (for workers/background processors)
|
|
124
|
-
*/
|
|
125
|
-
loadBalancer?: false | "public" | "internal";
|
|
126
|
-
/**
|
|
127
|
-
* Enable direct EC2 access without ALB.
|
|
128
|
-
* Uses host network mode for predictable ports.
|
|
129
|
-
* Access via EC2 public IP at container port.
|
|
130
|
-
*/
|
|
131
|
-
directAccess?: boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Advanced domain configuration for routing policies (latency, weighted, geo).
|
|
134
|
-
* Only used when domain is specified.
|
|
135
|
-
* Allows for multi-region deployments with advanced DNS routing.
|
|
136
|
-
*/
|
|
137
|
-
domainConfig?: DomainConfig;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Routing configuration for path/host-based routing on the ALB.
|
|
141
|
-
* Required when cluster has multiple services with ports.
|
|
142
|
-
* Optional for single service (gets all traffic automatically).
|
|
143
|
-
*/
|
|
144
|
-
export interface EcsRoutingConfig {
|
|
145
|
-
/**
|
|
146
|
-
* Path pattern for routing (e.g., "/api/*", "/users/*").
|
|
147
|
-
* Uses ALB path-based routing.
|
|
148
|
-
*/
|
|
149
|
-
path?: string;
|
|
150
|
-
/**
|
|
151
|
-
* Host header for routing (e.g., "api.example.com").
|
|
152
|
-
* Uses ALB host-based routing.
|
|
153
|
-
*/
|
|
154
|
-
host?: string;
|
|
155
|
-
/**
|
|
156
|
-
* Priority for this routing rule (1-50000).
|
|
157
|
-
* Lower number = higher priority.
|
|
158
|
-
* Auto-assigned if omitted.
|
|
159
|
-
*/
|
|
160
|
-
priority?: number;
|
|
161
|
-
/**
|
|
162
|
-
* Health check path for this service's target group.
|
|
163
|
-
* Default: "/"
|
|
164
|
-
*/
|
|
165
|
-
healthCheckPath?: string;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Configuration for a service in an ECS cluster.
|
|
169
|
-
* Each service gets its own task definition, scaling config, and target group.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* // Simple service
|
|
173
|
-
* { name: "api", containers: [{ port: 3000 }] }
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* // Service with routing (for multi-service clusters)
|
|
177
|
-
* { name: "users", containers: [{ port: 3000 }], routing: { path: "/users/*", priority: 100 } }
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* // Service with multiple routing rules (same target group)
|
|
181
|
-
* { name: "web", containers: [{ port: 3000 }], routing: [
|
|
182
|
-
* { path: "/api/v2/*", priority: 50 },
|
|
183
|
-
* { path: "/*", priority: 200 },
|
|
184
|
-
* ]}
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* // Service with sidecars
|
|
188
|
-
* {
|
|
189
|
-
* name: "api",
|
|
190
|
-
* containers: [
|
|
191
|
-
* { name: "app", port: 3000 },
|
|
192
|
-
* { name: "datadog", image: "datadog/agent" }
|
|
193
|
-
* ]
|
|
194
|
-
* }
|
|
195
|
-
*/
|
|
196
|
-
export interface EcsServiceConfig {
|
|
197
|
-
/** Service name (unique within cluster) */
|
|
198
|
-
name: string;
|
|
199
|
-
/**
|
|
200
|
-
* Container image for this service (applies to first container without explicit image).
|
|
201
|
-
* - Omit: Uses app's default ECR repository
|
|
202
|
-
* - string: ECR repository name or public image URL
|
|
203
|
-
* - Repository: CDK ECR Repository construct
|
|
204
|
-
*/
|
|
205
|
-
image?: string | Repository;
|
|
206
|
-
/**
|
|
207
|
-
* Container configuration(s) for this service.
|
|
208
|
-
* For single-container services, container name is optional and auto-generated.
|
|
209
|
-
* For multi-container services, the first container with a port is the primary container.
|
|
210
|
-
*/
|
|
211
|
-
containers?: EcsContainerConfig[];
|
|
212
|
-
/**
|
|
213
|
-
* Routing rules for this service on the cluster's ALB.
|
|
214
|
-
* Required when cluster has multiple services with ports.
|
|
215
|
-
* Optional for single service (gets /* automatically).
|
|
216
|
-
* Can be a single rule or an array of rules pointing to the same target group.
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* // Multiple routes for the same service
|
|
220
|
-
* routing: [
|
|
221
|
-
* { path: "/api/v2/*", priority: 50 },
|
|
222
|
-
* { path: "/*", priority: 200 },
|
|
223
|
-
* ]
|
|
224
|
-
*/
|
|
225
|
-
routing?: EcsRoutingConfig | EcsRoutingConfig[];
|
|
226
|
-
/** CPU units for this service's tasks (256-4096) */
|
|
227
|
-
cpu?: number;
|
|
228
|
-
/** Memory in MiB for this service's tasks (512-30720) */
|
|
229
|
-
memoryLimitMiB?: number;
|
|
230
|
-
/** Desired number of tasks. Default: 2 */
|
|
231
|
-
desiredCount?: number;
|
|
232
|
-
/**
|
|
233
|
-
* Scaling configuration.
|
|
234
|
-
* - Omit: enabled with defaults
|
|
235
|
-
* - false: disabled
|
|
236
|
-
*/
|
|
237
|
-
scaling?: EcsScalingConfig | false;
|
|
238
|
-
/**
|
|
239
|
-
* Path to Dockerfile for building this service's image.
|
|
240
|
-
* Metadata for CLI build process, not used during CDK synthesis.
|
|
241
|
-
*/
|
|
242
|
-
dockerfilePath?: string;
|
|
243
|
-
/**
|
|
244
|
-
* Docker build target stage for multi-stage Dockerfiles.
|
|
245
|
-
* When specified, the CLI builds with `--target <dockerTarget>`.
|
|
246
|
-
* The image tag suffix is also updated: `<service>-<target>-latest`.
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* // Dockerfile: FROM node AS base ... FROM base AS api ... FROM base AS worker
|
|
250
|
-
* { name: "api", dockerTarget: "api" } // builds: myapp-api-api-latest
|
|
251
|
-
* { name: "worker", dockerTarget: "worker" } // builds: myapp-worker-worker-latest
|
|
252
|
-
*/
|
|
253
|
-
dockerTarget?: string;
|
|
254
|
-
/**
|
|
255
|
-
* Additional inline policies for this service's task role.
|
|
256
|
-
* Added on top of the default ECS Exec permissions.
|
|
257
|
-
* Use for service-specific AWS permissions (S3, DynamoDB, SQS, etc.).
|
|
258
|
-
*/
|
|
259
|
-
taskRoleInlinePolicies?: Record<string, PolicyDocument>;
|
|
260
|
-
/**
|
|
261
|
-
* Additional managed policies for this service's task role.
|
|
262
|
-
* Added on top of the default ECS Exec permissions.
|
|
263
|
-
*/
|
|
264
|
-
taskRoleManagedPolicies?: IManagedPolicy[];
|
|
265
|
-
/**
|
|
266
|
-
* Resources this service needs to connect to (e.g., databases, S3 buckets, SQS queues).
|
|
267
|
-
* Creates security group rules for IConnectable resources and IAM grants for IAM resources.
|
|
268
|
-
* Follows least-privilege - only this service gets access, not all services in the cluster.
|
|
269
|
-
*
|
|
270
|
-
* Supports:
|
|
271
|
-
* - IConnectable: Security group resources (RDS, ECS, etc.)
|
|
272
|
-
* - IStorageConnector: S3 buckets (IAM grants)
|
|
273
|
-
* - IDynamoDBConnector: DynamoDB tables (IAM grants)
|
|
274
|
-
* - IQueueConnector: SQS queues (IAM grants)
|
|
275
|
-
* - ConnectionConfig: Explicit access level configuration
|
|
276
|
-
*
|
|
277
|
-
* @example
|
|
278
|
-
* // Simple connections (default permissions)
|
|
279
|
-
* connections: [database, bucket, cache, queue]
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* // Explicit access levels
|
|
283
|
-
* connections: [
|
|
284
|
-
* database, // Security group (RDS)
|
|
285
|
-
* { resource: cache, access: "read" }, // Read-only DynamoDB
|
|
286
|
-
* { resource: bucket, access: "write" }, // Write-only S3
|
|
287
|
-
* { resource: queue, access: "consume" } // Consume-only SQS
|
|
288
|
-
* ]
|
|
289
|
-
*/
|
|
290
|
-
connections?: ConnectionSpec[];
|
|
291
|
-
/**
|
|
292
|
-
* Capacity provider for this service. REQUIRED.
|
|
293
|
-
* Each service specifies its own capacity provider.
|
|
294
|
-
*
|
|
295
|
-
* @example
|
|
296
|
-
* // Mixed FARGATE and EC2 services in same cluster
|
|
297
|
-
* {
|
|
298
|
-
* services: [
|
|
299
|
-
* { name: "api", capacityProvider: "FARGATE" },
|
|
300
|
-
* { name: "worker", capacityProvider: "EC2", ec2Config: { instanceType: "t4g.micro" } }
|
|
301
|
-
* ]
|
|
302
|
-
* }
|
|
303
|
-
*/
|
|
304
|
-
capacityProvider: EcsCapacityProvider;
|
|
305
|
-
/**
|
|
306
|
-
* EC2 capacity configuration for this service.
|
|
307
|
-
* Only used when service capacityProvider is "EC2".
|
|
308
|
-
* Services with matching ec2Config share an ASG for efficiency.
|
|
309
|
-
*/
|
|
310
|
-
ec2Config?: Ec2CapacityConfig;
|
|
311
|
-
/**
|
|
312
|
-
* SSM Parameter Store path for secrets.
|
|
313
|
-
* If not specified, secrets are fetched from /<app>/<cluster>/<service>.
|
|
314
|
-
* Use this to override the default convention.
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* // Override default path
|
|
318
|
-
* ssmSecretsPath: "/custom/path/to/secrets"
|
|
319
|
-
*/
|
|
320
|
-
ssmSecretsPath?: string;
|
|
321
|
-
/**
|
|
322
|
-
* Per-service alarm configuration.
|
|
323
|
-
* - undefined: use defaults (CPU, memory, running tasks, 5xx if ALB)
|
|
324
|
-
* - false: disable alarms for this service
|
|
325
|
-
* - object: override specific thresholds
|
|
326
|
-
*/
|
|
327
|
-
alarms?: EcsServiceAlarmThresholds | false;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* ECS compute configuration.
|
|
331
|
-
* Creates an ECS cluster with one or more services sharing a load balancer.
|
|
332
|
-
*
|
|
333
|
-
* @example
|
|
334
|
-
* // Single service
|
|
335
|
-
* app.addCompute(ComputeFactory.build("WebApp", {
|
|
336
|
-
* type: "ecs",
|
|
337
|
-
* cluster: { domain: "app.example.com" },
|
|
338
|
-
* services: [{ name: "web", containers: [{ port: 3000 }] }]
|
|
339
|
-
* }));
|
|
340
|
-
*
|
|
341
|
-
* @example
|
|
342
|
-
* // Multi-service cluster with routing
|
|
343
|
-
* app.addCompute(ComputeFactory.build("ApiCluster", {
|
|
344
|
-
* type: "ecs",
|
|
345
|
-
* cluster: { domain: "api.example.com" },
|
|
346
|
-
* services: [
|
|
347
|
-
* { name: "users", containers: [{ port: 3000 }], routing: { path: "/users/*" } },
|
|
348
|
-
* { name: "orders", containers: [{ port: 3001 }], routing: { path: "/orders/*" } }
|
|
349
|
-
* ]
|
|
350
|
-
* }));
|
|
351
|
-
*
|
|
352
|
-
* @example
|
|
353
|
-
* // Internal workers (no ALB)
|
|
354
|
-
* app.addCompute(ComputeFactory.build("Workers", {
|
|
355
|
-
* type: "ecs",
|
|
356
|
-
* cluster: { loadBalancer: false },
|
|
357
|
-
* services: [{ name: "processor" }, { name: "emailer" }]
|
|
358
|
-
* }));
|
|
359
|
-
*/
|
|
360
|
-
export interface EcsComputeProps {
|
|
361
|
-
type: "ecs";
|
|
362
|
-
vpc?: IVpc;
|
|
363
|
-
/**
|
|
364
|
-
* Application name for SSM secrets namespace.
|
|
365
|
-
* When containers use secrets, the path is derived as: /<appName>/<clusterName>/<serviceName>
|
|
366
|
-
* Auto-derived from App.getName() if not specified.
|
|
367
|
-
*/
|
|
368
|
-
appName?: string;
|
|
369
|
-
/**
|
|
370
|
-
* Cluster configuration.
|
|
371
|
-
* Controls the shared ALB for all services in this cluster.
|
|
372
|
-
* - Omit: ALB created with default settings
|
|
373
|
-
* - `{ domain: "..." }`: ALB with HTTPS + DNS
|
|
374
|
-
* - `{ loadBalancer: false }`: No ALB (internal workers)
|
|
375
|
-
*/
|
|
376
|
-
cluster?: EcsClusterConfig;
|
|
377
|
-
/**
|
|
378
|
-
* Services in this cluster.
|
|
379
|
-
* Each service gets its own task definition, scaling, and target group.
|
|
380
|
-
* Each service MUST specify its own capacityProvider.
|
|
381
|
-
* All services share the cluster's ALB (unless disabled).
|
|
382
|
-
*/
|
|
383
|
-
services: EcsServiceConfig[];
|
|
384
|
-
/**
|
|
385
|
-
* ECR repository for all services (default image).
|
|
386
|
-
* Individual services can override with their own `image` property.
|
|
387
|
-
*/
|
|
388
|
-
ecrRepository?: Repository | RepositoryImage;
|
|
389
|
-
/**
|
|
390
|
-
* Path to Dockerfile for building custom image.
|
|
391
|
-
* Note: This is metadata for the CLI build process,
|
|
392
|
-
* not used during CDK synthesis.
|
|
393
|
-
*/
|
|
394
|
-
dockerfilePath?: string;
|
|
395
|
-
/**
|
|
396
|
-
* SNS topic for alarm notifications. Resolved to ITopic and passed to EcsCluster.
|
|
397
|
-
* Accepts either an ITopic directly or a topic ARN string (resolved internally).
|
|
398
|
-
*/
|
|
399
|
-
alertsTopic?: ITopic | string;
|
|
400
|
-
/** Application ID for alarm tagging (used by webhook to map alarms to applications). */
|
|
401
|
-
applicationId?: string;
|
|
402
|
-
}
|
|
403
13
|
/**
|
|
404
14
|
* Validates ECS-specific props.
|
|
405
15
|
* Extracted for clarity and detail parity with database/network patterns.
|
|
@@ -449,6 +59,7 @@ export declare class EcsCompute extends Construct implements IEcsCompute {
|
|
|
449
59
|
* Get the ALB listener if this is an ECS compute with ALB.
|
|
450
60
|
*/
|
|
451
61
|
getListener(): ApplicationListener | undefined;
|
|
62
|
+
getPrimaryListenerPort(): number | undefined;
|
|
452
63
|
/**
|
|
453
64
|
* Get the underlying ECS cluster construct.
|
|
454
65
|
*/
|
|
@@ -2,11 +2,12 @@ import { Grant } from "aws-cdk-lib/aws-iam";
|
|
|
2
2
|
import { Fn } from "aws-cdk-lib";
|
|
3
3
|
import { Construct } from "constructs";
|
|
4
4
|
import { Topic } from "aws-cdk-lib/aws-sns";
|
|
5
|
-
import EcsCluster
|
|
5
|
+
import EcsCluster from "../../resources/aws/compute/ecs.js";
|
|
6
6
|
import { FjallLogger } from "../../utils/validationLogger.js";
|
|
7
|
+
import { VALIDATION_PATTERNS } from "@fjall/generator";
|
|
7
8
|
import { COMPUTE_DEFAULTS } from "./compute.js";
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
export { ScalingType } from "./computeEcsTypes.js";
|
|
10
|
+
import { ScalingType } from "./computeEcsTypes.js";
|
|
10
11
|
export const ECS_CAPACITY_PROVIDER_CONFIG = {
|
|
11
12
|
FARGATE: {
|
|
12
13
|
usesSpot: false,
|
|
@@ -40,7 +41,7 @@ export function validateEcsProps(props) {
|
|
|
40
41
|
throw new Error(`Duplicate service names: ${[...new Set(duplicateNames)].join(", ")}`);
|
|
41
42
|
}
|
|
42
43
|
// Validate service name format
|
|
43
|
-
const invalidNames = props.services.filter((s) =>
|
|
44
|
+
const invalidNames = props.services.filter((s) => !VALIDATION_PATTERNS.ECS_SERVICE_NAME.test(s.name));
|
|
44
45
|
if (invalidNames.length > 0) {
|
|
45
46
|
throw new Error(`Invalid service names: ${invalidNames.map((s) => s.name).join(", ")}. ` +
|
|
46
47
|
"Service names must start with a letter and contain only letters, numbers, and hyphens.");
|
|
@@ -163,6 +164,7 @@ export class EcsCompute extends Construct {
|
|
|
163
164
|
taskRoleInlinePolicies: service.taskRoleInlinePolicies,
|
|
164
165
|
taskRoleManagedPolicies: service.taskRoleManagedPolicies,
|
|
165
166
|
connections: service.connections,
|
|
167
|
+
remoteConnections: service.remoteConnections,
|
|
166
168
|
capacityProvider: service.capacityProvider,
|
|
167
169
|
ec2Config: service.ec2Config,
|
|
168
170
|
ssmSecretsPath: service.ssmSecretsPath,
|
|
@@ -200,7 +202,7 @@ export class EcsCompute extends Construct {
|
|
|
200
202
|
alertsTopic: resolvedAlertsTopic,
|
|
201
203
|
applicationId: props.applicationId
|
|
202
204
|
};
|
|
203
|
-
this.ecsCluster = new EcsCluster(
|
|
205
|
+
this.ecsCluster = new EcsCluster(this, `${id}Ecs`, ecsProps);
|
|
204
206
|
this.connections = this.ecsCluster.connections;
|
|
205
207
|
}
|
|
206
208
|
/** Get the ECS cluster. */
|
|
@@ -222,12 +224,11 @@ export class EcsCompute extends Construct {
|
|
|
222
224
|
}
|
|
223
225
|
/** Get the security group for the cluster. */
|
|
224
226
|
getSecurityGroup() {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (securityGroups.length === 0) {
|
|
227
|
+
const sg = this.connections.securityGroups[0];
|
|
228
|
+
if (!sg) {
|
|
228
229
|
throw new Error("No security groups found for ECS cluster");
|
|
229
230
|
}
|
|
230
|
-
return
|
|
231
|
+
return sg;
|
|
231
232
|
}
|
|
232
233
|
/**
|
|
233
234
|
* Get the ALB listener if this is an ECS compute with ALB.
|
|
@@ -235,6 +236,9 @@ export class EcsCompute extends Construct {
|
|
|
235
236
|
getListener() {
|
|
236
237
|
return this.ecsCluster.getListener();
|
|
237
238
|
}
|
|
239
|
+
getPrimaryListenerPort() {
|
|
240
|
+
return this.getListener()?.port;
|
|
241
|
+
}
|
|
238
242
|
/**
|
|
239
243
|
* Get the underlying ECS cluster construct.
|
|
240
244
|
*/
|