@fjall/components-infrastructure 0.88.4 → 0.89.4

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/dist/lib/config/aws/disasterRecovery.js +28 -7
  3. package/dist/lib/patterns/aws/compute.d.ts +6 -716
  4. package/dist/lib/patterns/aws/compute.js +24 -427
  5. package/dist/lib/patterns/aws/computeEc2.d.ts +67 -0
  6. package/dist/lib/patterns/aws/computeEc2.js +46 -0
  7. package/dist/lib/patterns/aws/computeEcs.d.ts +446 -0
  8. package/dist/lib/patterns/aws/computeEcs.js +246 -0
  9. package/dist/lib/patterns/aws/computeLambda.d.ts +220 -0
  10. package/dist/lib/patterns/aws/computeLambda.js +147 -0
  11. package/dist/lib/patterns/aws/domainDelegation.d.ts +8 -0
  12. package/dist/lib/patterns/aws/domainDelegation.js +54 -0
  13. package/dist/lib/patterns/aws/domainFactory.d.ts +8 -0
  14. package/dist/lib/patterns/aws/domainFactory.js +23 -0
  15. package/dist/lib/patterns/aws/index.d.ts +3 -0
  16. package/dist/lib/patterns/aws/index.js +5 -1
  17. package/dist/lib/patterns/aws/interfaces/domain.d.ts +2 -0
  18. package/dist/lib/patterns/aws/interfaces/domain.js +6 -0
  19. package/dist/lib/patterns/aws/interfaces/index.d.ts +1 -0
  20. package/dist/lib/patterns/aws/interfaces/index.js +1 -1
  21. package/dist/lib/patterns/aws/interfaces/pattern.d.ts +3 -0
  22. package/dist/lib/patterns/aws/interfaces/pattern.js +1 -1
  23. package/dist/lib/patterns/aws/payload.js +11 -1
  24. package/dist/lib/resources/aws/compute/ecs.d.ts +14 -2
  25. package/dist/lib/resources/aws/compute/ecs.js +69 -24
  26. package/dist/lib/resources/aws/networking/domain.d.ts +13 -0
  27. package/dist/lib/resources/aws/networking/domain.js +102 -0
  28. package/dist/lib/resources/aws/networking/domainCertificate.d.ts +13 -0
  29. package/dist/lib/resources/aws/networking/domainCertificate.js +28 -0
  30. package/dist/lib/resources/aws/networking/hostedZone.js +3 -6
  31. package/dist/lib/resources/aws/networking/index.d.ts +2 -0
  32. package/dist/lib/resources/aws/networking/index.js +3 -1
  33. package/dist/lib/utils/capitaliseString.d.ts +1 -18
  34. package/dist/lib/utils/capitaliseString.js +8 -37
  35. package/dist/lib/utils/dnsRecords.d.ts +4 -0
  36. package/dist/lib/utils/dnsRecords.js +108 -0
  37. package/dist/lib/utils/domainTypes.d.ts +37 -0
  38. package/dist/lib/utils/domainTypes.js +10 -0
  39. package/dist/lib/utils/env.js +23 -29
  40. package/dist/lib/utils/getConfig.js +42 -16
  41. package/dist/lib/utils/index.d.ts +1 -0
  42. package/dist/lib/utils/index.js +2 -1
  43. package/package.json +4 -3
@@ -1,21 +1,12 @@
1
- import { type RepositoryImage, type ICluster, type IBaseService } from "aws-cdk-lib/aws-ecs";
2
- import { Repository } from "aws-cdk-lib/aws-ecr";
3
- import { Connections, type IVpc, type UserData, type IMachineImage, type ISecurityGroup } from "aws-cdk-lib/aws-ec2";
4
- import { Code, Runtime, Architecture, type FunctionUrlAuthType, type FunctionUrlCorsOptions, type IFunction, type InvokeMode } from "aws-cdk-lib/aws-lambda";
5
- import { type PolicyStatement, type PolicyDocument, type IManagedPolicy, type IGrantable, Grant } from "aws-cdk-lib/aws-iam";
6
- import { type IApplicationLoadBalancer, type ApplicationListener } from "aws-cdk-lib/aws-elasticloadbalancingv2";
7
- import { type IAutoScalingGroup } from "aws-cdk-lib/aws-autoscaling";
8
- import { Construct } from "constructs";
1
+ import { Runtime } from "aws-cdk-lib/aws-lambda";
2
+ import { type Construct } from "constructs";
9
3
  import { type IEcsCompute, type ILambdaCompute, type IEc2Compute, type AnyCompute, isCompute, isEcsCompute, isLambdaCompute, isEc2Compute } from "./interfaces/compute.js";
10
- import { type ConnectionSpec } from "./interfaces/connector.js";
11
4
  import type App from "../../app";
12
- import EcsCluster, { type EcsClusterProps, ScalingType, type DomainConfig, type EcsCapacityProvider, type Ec2CapacityConfig } from "../../resources/aws/compute/ecs";
13
- import { Ec2Instance } from "../../resources/aws/compute/ec2";
14
- import { LambdaFunction } from "../../resources/aws/compute/lambda";
15
- import { type SecretImport } from "../../resources/aws/secrets";
5
+ import { EcsCompute, type EcsComputeProps, type EcsServiceConfig, type EcsContainerConfig, type EcsScalingConfig, type EcsClusterConfig, type EcsRoutingConfig, type EcsCapacityProviderConfig, ECS_CAPACITY_PROVIDER_CONFIG, getEcsCapacityProviderConfig, ScalingType, type EcsCapacityProvider, type Ec2CapacityConfig, validateEcsProps, buildContainerConfigs, type ResolvedScalingConfig, resolveScalingConfig } from "./computeEcs.js";
6
+ import { LambdaCompute, type LambdaComputeProps, type ContainerLambdaProps, type CodeLambdaProps, type FunctionUrlConfig, type ResolvedLambdaDeployment, resolveLambdaDeployment, Architecture, HttpMethod, InvokeMode, type FunctionUrlCorsOptions } from "./computeLambda.js";
7
+ import { Ec2Compute, type Ec2ComputeProps, type SshConfig } from "./computeEc2.js";
8
+ export { EcsCompute, type EcsComputeProps, type EcsServiceConfig, type EcsContainerConfig, type EcsScalingConfig, type EcsClusterConfig, type EcsRoutingConfig, type EcsCapacityProviderConfig, ECS_CAPACITY_PROVIDER_CONFIG, getEcsCapacityProviderConfig, ScalingType, type EcsCapacityProvider, type Ec2CapacityConfig, validateEcsProps, buildContainerConfigs, type ResolvedScalingConfig, resolveScalingConfig, LambdaCompute, type LambdaComputeProps, type ContainerLambdaProps, type CodeLambdaProps, type FunctionUrlConfig, type ResolvedLambdaDeployment, resolveLambdaDeployment, Architecture, HttpMethod, InvokeMode, type FunctionUrlCorsOptions, Ec2Compute, type Ec2ComputeProps, type SshConfig };
16
9
  export type ComputeType = "ecs" | "ec2" | "lambda";
17
- export { ScalingType };
18
- export type { EcsCapacityProvider, Ec2CapacityConfig };
19
10
  /**
20
11
  * Configuration defaults for each compute type.
21
12
  */
@@ -31,16 +22,6 @@ export interface ComputeTypeConfig {
31
22
  requiresVpc: boolean;
32
23
  }
33
24
  export declare const COMPUTE_TYPE_CONFIG: Record<ComputeType, ComputeTypeConfig>;
34
- /**
35
- * Configuration for ECS capacity providers.
36
- */
37
- export interface EcsCapacityProviderConfig {
38
- /** Whether this uses Spot pricing */
39
- usesSpot: boolean;
40
- /** Whether this runs on EC2 instances (vs serverless Fargate) */
41
- usesEc2Instances: boolean;
42
- }
43
- export declare const ECS_CAPACITY_PROVIDER_CONFIG: Record<EcsCapacityProvider, EcsCapacityProviderConfig>;
44
25
  /**
45
26
  * Default values for compute resource configuration.
46
27
  * Centralised constants to ensure consistency across the codebase.
@@ -64,615 +45,10 @@ export declare const COMPUTE_DEFAULTS: {
64
45
  };
65
46
  };
66
47
  export declare function getComputeTypeConfig(type: ComputeType): ComputeTypeConfig;
67
- export declare function getEcsCapacityProviderConfig(provider: EcsCapacityProvider): EcsCapacityProviderConfig;
68
- export { Architecture, HttpMethod, InvokeMode, type FunctionUrlCorsOptions } from "aws-cdk-lib/aws-lambda";
69
- /**
70
- * Configuration for a container in an ECS task.
71
- *
72
- * For single-container services, `name` is optional and defaults to `${serviceName}Container`.
73
- * For multi-container tasks, the first container with a `port` is the **primary container**
74
- * that receives load balancer traffic.
75
- *
76
- * @example
77
- * // Single container (name auto-generated)
78
- * containers: [{ port: 3000 }]
79
- *
80
- * @example
81
- * // Multi-container with sidecars
82
- * containers: [
83
- * { name: "app", port: 3000 }, // Primary - receives ALB traffic
84
- * { name: "datadog", image: "datadog/agent" } // Sidecar - monitoring
85
- * ]
86
- */
87
- export interface EcsContainerConfig {
88
- /** Container name. Optional for single-container services. */
89
- name?: string;
90
- /**
91
- * Container image. Options:
92
- * - Omit: Uses app's default ECR repository (primary container only)
93
- * - string: ECR repository name or public image URL
94
- * - Repository: CDK ECR Repository construct
95
- */
96
- image?: string | Repository;
97
- /**
98
- * Port the container listens on.
99
- * The first container with a port becomes the **primary container**
100
- * and is registered with the load balancer.
101
- */
102
- port?: number;
103
- /** Environment variables */
104
- environment?: Record<string, string>;
105
- /**
106
- * Secrets from AWS SSM Parameter Store.
107
- * Array of secret names that will be fetched from the service's SSM namespace.
108
- * The namespace path is auto-determined from app/cluster/service names.
109
- *
110
- * @example
111
- * // Secrets at /myapp/api-cluster/users/API_KEY and /myapp/api-cluster/users/DB_PASSWORD
112
- * secrets: ["API_KEY", "DB_PASSWORD"]
113
- */
114
- secrets?: string[];
115
- /** Secrets imported from other CDK resources (AWS Secrets Manager) */
116
- secretsImport?: Record<string, SecretImport>;
117
- /** Command to run in the container */
118
- command?: string[];
119
- /** Entry point for the container */
120
- entryPoint?: string[];
121
- /**
122
- * Whether this container is essential.
123
- * If an essential container stops, all containers in the task stop.
124
- * Default: true
125
- */
126
- essential?: boolean;
127
- /**
128
- * Health check configuration.
129
- * Default: For primary container with port, uses curl health check.
130
- */
131
- healthCheck?: {
132
- command: string[];
133
- interval?: number;
134
- timeout?: number;
135
- retries?: number;
136
- startPeriod?: number;
137
- };
138
- }
139
- /**
140
- * ECS scaling configuration.
141
- * - Omit: enabled with defaults
142
- * - `{}`: enabled with defaults
143
- * - `{ minCapacity: 2, maxCapacity: 10 }`: custom scaling
144
- * - `false`: explicitly disabled
145
- */
146
- export interface EcsScalingConfig {
147
- minCapacity?: number;
148
- maxCapacity?: number;
149
- scalingType?: ScalingType;
150
- }
151
- /**
152
- * Cluster-level configuration.
153
- * Controls the shared ALB for all services in this cluster.
154
- */
155
- export interface EcsClusterConfig {
156
- /**
157
- * Domain for HTTPS access.
158
- * - Omit: ALB created with default DNS (*.elb.amazonaws.com)
159
- * - Specified: Creates ACM certificate + Route53 DNS A record
160
- */
161
- domain?: string;
162
- /**
163
- * Load balancer configuration.
164
- * - Omit or "public": Internet-facing ALB (default)
165
- * - "internal": VPC-only ALB
166
- * - false: No ALB (for workers/background processors)
167
- */
168
- loadBalancer?: false | "public" | "internal";
169
- /**
170
- * Enable direct EC2 access without ALB.
171
- * Uses host network mode for predictable ports.
172
- * Access via EC2 public IP at container port.
173
- */
174
- directAccess?: boolean;
175
- /**
176
- * Advanced domain configuration for routing policies (latency, weighted, geo).
177
- * Only used when domain is specified.
178
- * Allows for multi-region deployments with advanced DNS routing.
179
- */
180
- domainConfig?: DomainConfig;
181
- }
182
- /**
183
- * Routing configuration for path/host-based routing on the ALB.
184
- * Required when cluster has multiple services with ports.
185
- * Optional for single service (gets all traffic automatically).
186
- */
187
- export interface EcsRoutingConfig {
188
- /**
189
- * Path pattern for routing (e.g., "/api/*", "/users/*").
190
- * Uses ALB path-based routing.
191
- */
192
- path?: string;
193
- /**
194
- * Host header for routing (e.g., "api.example.com").
195
- * Uses ALB host-based routing.
196
- */
197
- host?: string;
198
- /**
199
- * Priority for this routing rule (1-50000).
200
- * Lower number = higher priority.
201
- * Auto-assigned if omitted.
202
- */
203
- priority?: number;
204
- /**
205
- * Health check path for this service's target group.
206
- * Default: "/"
207
- */
208
- healthCheckPath?: string;
209
- }
210
- /**
211
- * Configuration for a service in an ECS cluster.
212
- * Each service gets its own task definition, scaling config, and target group.
213
- *
214
- * @example
215
- * // Simple service
216
- * { name: "api", containers: [{ port: 3000 }] }
217
- *
218
- * @example
219
- * // Service with routing (for multi-service clusters)
220
- * { name: "users", containers: [{ port: 3000 }], routing: { path: "/users/*", priority: 100 } }
221
- *
222
- * @example
223
- * // Service with multiple routing rules (same target group)
224
- * { name: "web", containers: [{ port: 3000 }], routing: [
225
- * { path: "/api/v2/*", priority: 50 },
226
- * { path: "/*", priority: 200 },
227
- * ]}
228
- *
229
- * @example
230
- * // Service with sidecars
231
- * {
232
- * name: "api",
233
- * containers: [
234
- * { name: "app", port: 3000 },
235
- * { name: "datadog", image: "datadog/agent" }
236
- * ]
237
- * }
238
- */
239
- export interface EcsServiceConfig {
240
- /** Service name (unique within cluster) */
241
- name: string;
242
- /**
243
- * Container image for this service (applies to first container without explicit image).
244
- * - Omit: Uses app's default ECR repository
245
- * - string: ECR repository name or public image URL
246
- * - Repository: CDK ECR Repository construct
247
- */
248
- image?: string | Repository;
249
- /**
250
- * Container configuration(s) for this service.
251
- * For single-container services, container name is optional and auto-generated.
252
- * For multi-container services, the first container with a port is the primary container.
253
- */
254
- containers?: EcsContainerConfig[];
255
- /**
256
- * Routing rules for this service on the cluster's ALB.
257
- * Required when cluster has multiple services with ports.
258
- * Optional for single service (gets /* automatically).
259
- * Can be a single rule or an array of rules pointing to the same target group.
260
- *
261
- * @example
262
- * // Multiple routes for the same service
263
- * routing: [
264
- * { path: "/api/v2/*", priority: 50 },
265
- * { path: "/*", priority: 200 },
266
- * ]
267
- */
268
- routing?: EcsRoutingConfig | EcsRoutingConfig[];
269
- /** CPU units for this service's tasks (256-4096) */
270
- cpu?: number;
271
- /** Memory in MiB for this service's tasks (512-30720) */
272
- memoryLimitMiB?: number;
273
- /** Desired number of tasks. Default: 2 */
274
- desiredCount?: number;
275
- /**
276
- * Scaling configuration.
277
- * - Omit: enabled with defaults
278
- * - false: disabled
279
- */
280
- scaling?: EcsScalingConfig | false;
281
- /**
282
- * Path to Dockerfile for building this service's image.
283
- * Metadata for CLI build process, not used during CDK synthesis.
284
- */
285
- dockerfilePath?: string;
286
- /**
287
- * Docker build target stage for multi-stage Dockerfiles.
288
- * When specified, the CLI builds with `--target <dockerTarget>`.
289
- * The image tag suffix is also updated: `<service>-<target>-latest`.
290
- *
291
- * @example
292
- * // Dockerfile: FROM node AS base ... FROM base AS api ... FROM base AS worker
293
- * { name: "api", dockerTarget: "api" } // builds: myapp-api-api-latest
294
- * { name: "worker", dockerTarget: "worker" } // builds: myapp-worker-worker-latest
295
- */
296
- dockerTarget?: string;
297
- /**
298
- * Additional inline policies for this service's task role.
299
- * Added on top of the default ECS Exec permissions.
300
- * Use for service-specific AWS permissions (S3, DynamoDB, SQS, etc.).
301
- */
302
- taskRoleInlinePolicies?: Record<string, PolicyDocument>;
303
- /**
304
- * Additional managed policies for this service's task role.
305
- * Added on top of the default ECS Exec permissions.
306
- */
307
- taskRoleManagedPolicies?: IManagedPolicy[];
308
- /**
309
- * Resources this service needs to connect to (e.g., databases, S3 buckets, SQS queues).
310
- * Creates security group rules for IConnectable resources and IAM grants for IAM resources.
311
- * Follows least-privilege - only this service gets access, not all services in the cluster.
312
- *
313
- * Supports:
314
- * - IConnectable: Security group resources (RDS, ECS, etc.)
315
- * - IStorageConnector: S3 buckets (IAM grants)
316
- * - IDynamoDBConnector: DynamoDB tables (IAM grants)
317
- * - IQueueConnector: SQS queues (IAM grants)
318
- * - ConnectionConfig: Explicit access level configuration
319
- *
320
- * @example
321
- * // Simple connections (default permissions)
322
- * connections: [database, bucket, cache, queue]
323
- *
324
- * @example
325
- * // Explicit access levels
326
- * connections: [
327
- * database, // Security group (RDS)
328
- * { resource: cache, access: "read" }, // Read-only DynamoDB
329
- * { resource: bucket, access: "write" }, // Write-only S3
330
- * { resource: queue, access: "consume" } // Consume-only SQS
331
- * ]
332
- */
333
- connections?: ConnectionSpec[];
334
- /**
335
- * Capacity provider for this service. REQUIRED.
336
- * Each service specifies its own capacity provider.
337
- *
338
- * @example
339
- * // Mixed FARGATE and EC2 services in same cluster
340
- * {
341
- * services: [
342
- * { name: "api", capacityProvider: "FARGATE" },
343
- * { name: "worker", capacityProvider: "EC2", ec2Config: { instanceType: "t4g.micro" } }
344
- * ]
345
- * }
346
- */
347
- capacityProvider: EcsCapacityProvider;
348
- /**
349
- * EC2 capacity configuration for this service.
350
- * Only used when service capacityProvider is "EC2".
351
- * Services with matching ec2Config share an ASG for efficiency.
352
- */
353
- ec2Config?: Ec2CapacityConfig;
354
- /**
355
- * SSM Parameter Store path for secrets.
356
- * If not specified, secrets are fetched from /<app>/<cluster>/<service>.
357
- * Use this to override the default convention.
358
- *
359
- * @example
360
- * // Override default path
361
- * ssmSecretsPath: "/custom/path/to/secrets"
362
- */
363
- ssmSecretsPath?: string;
364
- }
365
- /**
366
- * SSH access configuration for EC2 instances.
367
- * - Omit: disabled (default)
368
- * - `{}`: enabled with auto-generated key
369
- * - `{ keyName: "my-key" }`: enabled with existing key
370
- * - `false`: explicitly disabled
371
- */
372
- export interface SshConfig {
373
- /** SSH key pair name */
374
- keyName?: string;
375
- /** Allowed CIDR blocks for SSH access */
376
- allowedCidrs?: string[];
377
- }
378
- /**
379
- * Lambda function URL configuration.
380
- * - Omit: disabled (default)
381
- * - `{}`: enabled with IAM auth
382
- * - `{ authType: "NONE", cors: {...} }`: public with CORS
383
- * - `false`: explicitly disabled
384
- */
385
- export interface FunctionUrlConfig {
386
- /** Authentication type. Default: AWS_IAM */
387
- authType?: FunctionUrlAuthType;
388
- /** CORS configuration */
389
- cors?: FunctionUrlCorsOptions;
390
- /** Invoke mode. Use RESPONSE_STREAM for Lambda streaming. Default: BUFFERED */
391
- invokeMode?: InvokeMode;
392
- }
393
- interface BaseComputeProps {
394
- vpc?: IVpc;
395
- }
396
- /**
397
- * ECS compute configuration.
398
- * Creates an ECS cluster with one or more services sharing a load balancer.
399
- *
400
- * @example
401
- * // Single service
402
- * app.addCompute(ComputeFactory.build("WebApp", {
403
- * type: "ecs",
404
- * cluster: { domain: "app.example.com" },
405
- * services: [{ name: "web", containers: [{ port: 3000 }] }]
406
- * }));
407
- *
408
- * @example
409
- * // Multi-service cluster with routing
410
- * app.addCompute(ComputeFactory.build("ApiCluster", {
411
- * type: "ecs",
412
- * cluster: { domain: "api.example.com" },
413
- * services: [
414
- * { name: "users", containers: [{ port: 3000 }], routing: { path: "/users/*" } },
415
- * { name: "orders", containers: [{ port: 3001 }], routing: { path: "/orders/*" } }
416
- * ]
417
- * }));
418
- *
419
- * @example
420
- * // Internal workers (no ALB)
421
- * app.addCompute(ComputeFactory.build("Workers", {
422
- * type: "ecs",
423
- * cluster: { loadBalancer: false },
424
- * services: [{ name: "processor" }, { name: "emailer" }]
425
- * }));
426
- */
427
- export interface EcsComputeProps extends BaseComputeProps {
428
- type: "ecs";
429
- /**
430
- * Application name for SSM secrets namespace.
431
- * When containers use secrets, the path is derived as: /<appName>/<clusterName>/<serviceName>
432
- * Auto-derived from App.getName() if not specified.
433
- */
434
- appName?: string;
435
- /**
436
- * Cluster configuration.
437
- * Controls the shared ALB for all services in this cluster.
438
- * - Omit: ALB created with default settings
439
- * - `{ domain: "..." }`: ALB with HTTPS + DNS
440
- * - `{ loadBalancer: false }`: No ALB (internal workers)
441
- */
442
- cluster?: EcsClusterConfig;
443
- /**
444
- * Services in this cluster.
445
- * Each service gets its own task definition, scaling, and target group.
446
- * Each service MUST specify its own capacityProvider.
447
- * All services share the cluster's ALB (unless disabled).
448
- */
449
- services: EcsServiceConfig[];
450
- /**
451
- * ECR repository for all services (default image).
452
- * Individual services can override with their own `image` property.
453
- */
454
- ecrRepository?: Repository | RepositoryImage;
455
- /**
456
- * Path to Dockerfile for building custom image.
457
- * Note: This is metadata for the CLI build process,
458
- * not used during CDK synthesis.
459
- */
460
- dockerfilePath?: string;
461
- }
462
- export interface Ec2ComputeProps extends BaseComputeProps {
463
- type: "ec2";
464
- /** EC2 instance type. Default: "t4g.micro" */
465
- instanceType?: string;
466
- /**
467
- * SSH access configuration.
468
- * - Omit: disabled (default)
469
- * - `{}`: enabled with defaults
470
- * - `false`: explicitly disabled
471
- */
472
- ssh?: SshConfig | false;
473
- /** User data script */
474
- userData?: UserData;
475
- /** Machine image (AMI) */
476
- machineImage?: IMachineImage;
477
- /** Minimum number of instances. Default: 1 */
478
- minCapacity?: number;
479
- /** Maximum number of instances. Default: 1 */
480
- maxCapacity?: number;
481
- /**
482
- * Percentage of capacity to run on Spot instances (0-100).
483
- * - Omit or 0: All On-Demand instances (default)
484
- * - 100: All Spot instances
485
- * - 50: Half Spot, half On-Demand
486
- *
487
- * Spot instances can reduce costs by up to 90% but may be interrupted.
488
- * Use for fault-tolerant workloads.
489
- */
490
- spotCapacityPercentage?: number;
491
- }
492
- /**
493
- * Base Lambda configuration shared by both container and code deployments.
494
- */
495
- interface BaseLambdaProps extends BaseComputeProps {
496
- type: "lambda";
497
- /** Timeout in seconds. Default: 3 */
498
- timeout?: number;
499
- /** Memory size in MB. Default: 128 */
500
- memorySize?: number;
501
- ephemeralStorageSize?: number;
502
- /** CPU architecture. Default: x86_64. Use Architecture.ARM_64 for Graviton2. */
503
- architecture?: Architecture;
504
- /** Lambda function description */
505
- description?: string;
506
- /** IAM role description */
507
- roleDescription?: string;
508
- /** Inline IAM policy statements */
509
- inlinePolicy?: PolicyStatement[];
510
- /**
511
- * Function URL configuration.
512
- * - Omit: disabled (default)
513
- * - `{}`: enabled with IAM auth
514
- * - `{ authType: "NONE" }`: public access
515
- * - `false`: explicitly disabled
516
- */
517
- functionUrl?: FunctionUrlConfig | false;
518
- /** Environment variables */
519
- environment?: Record<string, string>;
520
- /**
521
- * Secrets from AWS SSM Parameter Store.
522
- * Array of secret names that will be fetched from the Lambda's SSM namespace.
523
- * The namespace path is auto-determined as: /<appName>/lambda/<functionName>
524
- *
525
- * @example
526
- * secrets: ["API_KEY", "STRIPE_SECRET"]
527
- */
528
- secrets?: string[];
529
- /**
530
- * SSM Parameter Store path for secrets.
531
- * If secrets are defined, this path is used as the base path.
532
- * If not specified, uses: /<appName>/lambda/<functionName>
533
- *
534
- * @example
535
- * ssmSecretsPath: "/myapp/custom/path"
536
- */
537
- ssmSecretsPath?: string;
538
- /**
539
- * Secrets imported from other CDK resources (AWS Secrets Manager).
540
- * Used for CDK-managed secrets like database credentials.
541
- *
542
- * @example
543
- * secretsImport: {
544
- * DATABASE_USERNAME: database.getCredentials().getImport("username"),
545
- * DATABASE_PASSWORD: database.getCredentials().getImport("password")
546
- * }
547
- */
548
- secretsImport?: Record<string, SecretImport>;
549
- /**
550
- * Application name for SSM secrets path derivation.
551
- * Auto-derived from App instance when using ComputeFactory.
552
- * Only specify for advanced use cases.
553
- */
554
- appName?: string;
555
- /**
556
- * Resources this Lambda needs to connect to (e.g., databases, S3 buckets, SQS queues).
557
- * Creates security group rules for IConnectable resources and IAM grants for IAM resources.
558
- *
559
- * Supports:
560
- * - IConnectable: Security group resources (RDS, ECS, etc.)
561
- * - IStorageConnector: S3 buckets (IAM grants)
562
- * - IDynamoDBConnector: DynamoDB tables (IAM grants)
563
- * - IQueueConnector: SQS queues (IAM grants)
564
- * - ConnectionConfig: Explicit access level configuration
565
- *
566
- * @example
567
- * connections: [
568
- * database,
569
- * { resource: queue, access: "send" }
570
- * ]
571
- */
572
- connections?: ConnectionSpec[];
573
- /**
574
- * EventBridge schedule expression for scheduled Lambda invocations.
575
- * Uses cron or rate syntax: "rate(1 hour)" or "cron(0 12 * * ? *)".
576
- */
577
- scheduleExpression?: string;
578
- }
579
- /**
580
- * Container-based Lambda using ECR image.
581
- *
582
- * Uses Docker image from ECR repository. Handler and runtime are
583
- * automatically set to FROM_IMAGE.
584
- *
585
- * @example
586
- * app.addCompute(ComputeFactory.build("ImageLambda", {
587
- * type: "lambda",
588
- * deployment: "container",
589
- * ecrRepository: app.getDefaultContainerRegistry()
590
- * }));
591
- */
592
- export interface ContainerLambdaProps extends BaseLambdaProps {
593
- /** Container-based deployment using ECR image */
594
- deployment: "container";
595
- /** ECR repository containing the Lambda container image */
596
- ecrRepository: Repository | RepositoryImage;
597
- }
598
- /**
599
- * Code-based Lambda using inline code or S3.
600
- *
601
- * Uses traditional Lambda deployment with code, handler, and runtime.
602
- *
603
- * @example
604
- * app.addCompute(ComputeFactory.build("CodeLambda", {
605
- * type: "lambda",
606
- * deployment: "code",
607
- * code: Code.fromAsset("./lambda"),
608
- * handler: "index.handler",
609
- * runtime: Runtime.NODEJS_20_X
610
- * }));
611
- */
612
- export interface CodeLambdaProps extends BaseLambdaProps {
613
- /** Code-based deployment */
614
- deployment: "code";
615
- /** Lambda code (from asset, S3, or inline) */
616
- code: Code;
617
- /** Handler function. Default: "index.handler" */
618
- handler?: string;
619
- /** Lambda runtime. Default: NODEJS_22_X */
620
- runtime?: Runtime;
621
- }
622
- /**
623
- * Lambda compute configuration.
624
- *
625
- * Discriminated union ensuring type-safe Lambda configuration:
626
- * - `deployment: "container"` requires `ecrRepository`
627
- * - `deployment: "code"` requires `code` and allows `handler`/`runtime`
628
- *
629
- * @example
630
- * // Container-based Lambda
631
- * { type: "lambda", deployment: "container", ecrRepository: ecr }
632
- *
633
- * @example
634
- * // Code-based Lambda
635
- * { type: "lambda", deployment: "code", code: Code.fromAsset("./lambda") }
636
- */
637
- export type LambdaComputeProps = ContainerLambdaProps | CodeLambdaProps;
638
48
  export type IEcsComputeProps = EcsComputeProps;
639
49
  export type ILambdaComputeProps = LambdaComputeProps;
640
50
  export type IEc2ComputeProps = Ec2ComputeProps;
641
51
  export type IComputeProps = IEcsComputeProps | ILambdaComputeProps | IEc2ComputeProps;
642
- /**
643
- * Build container configurations for an ECS service.
644
- * Converts user-facing EcsContainerConfig to internal EcsClusterProps format.
645
- * @internal Exported for testing only
646
- */
647
- export declare function buildContainerConfigs(service: EcsServiceConfig): EcsClusterProps["services"][number]["containers"];
648
- /**
649
- * Resolved scaling configuration for an ECS service.
650
- * @internal Exported for testing only
651
- */
652
- export interface ResolvedScalingConfig {
653
- scalingType: ScalingType | undefined;
654
- minCapacity: number | undefined;
655
- maxCapacity: number | undefined;
656
- }
657
- /**
658
- * Resolve scaling configuration from service props.
659
- * Handles the three cases: explicit config, disabled (false), or default (undefined).
660
- * @internal Exported for testing only
661
- */
662
- export declare function resolveScalingConfig(scaling: EcsScalingConfig | false | undefined): ResolvedScalingConfig;
663
- /**
664
- * Resolved Lambda deployment configuration.
665
- */
666
- export interface ResolvedLambdaDeployment {
667
- code: Code;
668
- handler: string;
669
- runtime: Runtime;
670
- }
671
- /**
672
- * Resolve Lambda deployment configuration from props.
673
- * Handles container vs code deployment types.
674
- */
675
- export declare function resolveLambdaDeployment(props: ILambdaComputeProps): ResolvedLambdaDeployment;
676
52
  /**
677
53
  * Factory for creating compute resources with type-safe return types.
678
54
  *
@@ -710,91 +86,5 @@ export declare class ComputeFactory {
710
86
  static build(id: string, props: ILambdaComputeProps): (app: App, scope: Construct) => LambdaCompute;
711
87
  static build(id: string, props: IEc2ComputeProps): (app: App, scope: Construct) => Ec2Compute;
712
88
  }
713
- /**
714
- * ECS compute wrapper implementing IEcsCompute.
715
- * Provides type-safe access to ECS-specific resources.
716
- */
717
- export declare class EcsCompute extends Construct implements IEcsCompute {
718
- readonly computeType: "ecs";
719
- readonly connections: Connections;
720
- private readonly ecsCluster;
721
- constructor(scope: Construct, id: string, props: IEcsComputeProps);
722
- /** Get the ECS cluster. */
723
- getCluster(): ICluster;
724
- /** Get the Application Load Balancer if one was created. */
725
- getLoadBalancer(): IApplicationLoadBalancer | undefined;
726
- /** Get a specific service by name. */
727
- getService(name: string): IBaseService | undefined;
728
- /** Get all services in the cluster. */
729
- getAllServices(): IBaseService[];
730
- /** Get the security group for the cluster. */
731
- getSecurityGroup(): ISecurityGroup;
732
- /**
733
- * Get the ALB listener if this is an ECS compute with ALB.
734
- */
735
- getListener(): ApplicationListener | undefined;
736
- /**
737
- * Get the underlying ECS cluster construct.
738
- */
739
- getEcsCluster(): EcsCluster;
740
- /**
741
- * Grants ecs:ExecuteCommand permission for ECS services.
742
- * Uses wildcard resource because ecs:ExecuteCommand targets task ARNs
743
- * which are not known until runtime (tasks are ephemeral).
744
- */
745
- grantExecuteCommand(grantee: IGrantable): Grant;
746
- }
747
- /**
748
- * Lambda compute wrapper implementing ILambdaCompute.
749
- * Provides type-safe access to Lambda-specific resources.
750
- */
751
- export declare class LambdaCompute extends Construct implements ILambdaCompute {
752
- readonly computeType: "lambda";
753
- readonly connections: Connections;
754
- private readonly lambdaFunction;
755
- constructor(scope: Construct, id: string, props: ILambdaComputeProps);
756
- /**
757
- * Get a Lambda function by name.
758
- * Since we only have one function, name is ignored.
759
- */
760
- getFunction(_name?: string): IFunction | undefined;
761
- /** Get all Lambda functions. */
762
- getAllFunctions(): IFunction[];
763
- /**
764
- * Get the function URL for a Lambda function.
765
- */
766
- getFunctionUrl(_name?: string): string | undefined;
767
- /**
768
- * Grant invoke permissions to a grantee.
769
- */
770
- grantInvoke(grantee: IGrantable, _functionName?: string): Grant;
771
- /**
772
- * Get the security group for VPC-enabled Lambda functions.
773
- * Returns undefined if the Lambda is not VPC-enabled.
774
- */
775
- getSecurityGroup(): ISecurityGroup | undefined;
776
- /**
777
- * Get the underlying Lambda function construct.
778
- */
779
- getLambdaFunction(): LambdaFunction;
780
- }
781
- /**
782
- * EC2 compute wrapper implementing IEc2Compute.
783
- * Provides type-safe access to EC2-specific resources.
784
- */
785
- export declare class Ec2Compute extends Construct implements IEc2Compute {
786
- readonly computeType: "ec2";
787
- readonly connections: Connections;
788
- private readonly ec2Instance;
789
- constructor(scope: Construct, id: string, props: IEc2ComputeProps);
790
- /** Get the Auto Scaling Group. */
791
- getAutoScalingGroup(): IAutoScalingGroup;
792
- /** Get the security group. */
793
- getSecurityGroup(): ISecurityGroup;
794
- /**
795
- * Get the underlying EC2 instance construct.
796
- */
797
- getEc2Instance(): Ec2Instance;
798
- }
799
89
  export { isCompute, isEcsCompute, isLambdaCompute, isEc2Compute };
800
90
  export type { IEcsCompute, ILambdaCompute, IEc2Compute, AnyCompute };