@dga-itc/aws-cdk-constructs 1.0.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.
Files changed (82) hide show
  1. package/README.md +219 -0
  2. package/dist/aws-cdk/constructs/acm.d.ts +28 -0
  3. package/dist/aws-cdk/constructs/acm.js +239 -0
  4. package/dist/aws-cdk/constructs/alb.d.ts +28 -0
  5. package/dist/aws-cdk/constructs/alb.js +304 -0
  6. package/dist/aws-cdk/constructs/bastion.d.ts +46 -0
  7. package/dist/aws-cdk/constructs/bastion.js +332 -0
  8. package/dist/aws-cdk/constructs/cloudfront.d.ts +45 -0
  9. package/dist/aws-cdk/constructs/cloudfront.js +261 -0
  10. package/dist/aws-cdk/constructs/ecr.d.ts +17 -0
  11. package/dist/aws-cdk/constructs/ecr.js +143 -0
  12. package/dist/aws-cdk/constructs/ecs-cluster.d.ts +21 -0
  13. package/dist/aws-cdk/constructs/ecs-cluster.js +124 -0
  14. package/dist/aws-cdk/constructs/ecs-service.d.ts +72 -0
  15. package/dist/aws-cdk/constructs/ecs-service.js +682 -0
  16. package/dist/aws-cdk/constructs/efs.d.ts +31 -0
  17. package/dist/aws-cdk/constructs/efs.js +241 -0
  18. package/dist/aws-cdk/constructs/elasticache.d.ts +35 -0
  19. package/dist/aws-cdk/constructs/elasticache.js +210 -0
  20. package/dist/aws-cdk/constructs/nacl.d.ts +37 -0
  21. package/dist/aws-cdk/constructs/nacl.js +88 -0
  22. package/dist/aws-cdk/constructs/nlb.d.ts +39 -0
  23. package/dist/aws-cdk/constructs/nlb.js +276 -0
  24. package/dist/aws-cdk/constructs/rds.d.ts +40 -0
  25. package/dist/aws-cdk/constructs/rds.js +320 -0
  26. package/dist/aws-cdk/constructs/self-signed-cert.d.ts +83 -0
  27. package/dist/aws-cdk/constructs/self-signed-cert.js +215 -0
  28. package/dist/aws-cdk/constructs/sqs.d.ts +30 -0
  29. package/dist/aws-cdk/constructs/sqs.js +268 -0
  30. package/dist/aws-cdk/constructs/vpc.d.ts +30 -0
  31. package/dist/aws-cdk/constructs/vpc.js +423 -0
  32. package/dist/aws-cdk/constructs/waf.d.ts +37 -0
  33. package/dist/aws-cdk/constructs/waf.js +350 -0
  34. package/dist/aws-cdk/interfaces/account-config.d.ts +18 -0
  35. package/dist/aws-cdk/interfaces/account-config.js +2 -0
  36. package/dist/aws-cdk/interfaces/acm-config.d.ts +94 -0
  37. package/dist/aws-cdk/interfaces/acm-config.js +14 -0
  38. package/dist/aws-cdk/interfaces/alb-config.d.ts +72 -0
  39. package/dist/aws-cdk/interfaces/alb-config.js +2 -0
  40. package/dist/aws-cdk/interfaces/bastion-config.d.ts +77 -0
  41. package/dist/aws-cdk/interfaces/bastion-config.js +10 -0
  42. package/dist/aws-cdk/interfaces/cloudfront-config.d.ts +154 -0
  43. package/dist/aws-cdk/interfaces/cloudfront-config.js +15 -0
  44. package/dist/aws-cdk/interfaces/ecr-config.d.ts +40 -0
  45. package/dist/aws-cdk/interfaces/ecr-config.js +2 -0
  46. package/dist/aws-cdk/interfaces/ecs-cluster-config.d.ts +30 -0
  47. package/dist/aws-cdk/interfaces/ecs-cluster-config.js +2 -0
  48. package/dist/aws-cdk/interfaces/ecs-service-config.d.ts +237 -0
  49. package/dist/aws-cdk/interfaces/ecs-service-config.js +2 -0
  50. package/dist/aws-cdk/interfaces/efs-config.d.ts +56 -0
  51. package/dist/aws-cdk/interfaces/efs-config.js +7 -0
  52. package/dist/aws-cdk/interfaces/elasticache-config.d.ts +56 -0
  53. package/dist/aws-cdk/interfaces/elasticache-config.js +7 -0
  54. package/dist/aws-cdk/interfaces/nacl-config.d.ts +1 -0
  55. package/dist/aws-cdk/interfaces/nacl-config.js +3 -0
  56. package/dist/aws-cdk/interfaces/nlb-config.d.ts +69 -0
  57. package/dist/aws-cdk/interfaces/nlb-config.js +2 -0
  58. package/dist/aws-cdk/interfaces/rds-config.d.ts +84 -0
  59. package/dist/aws-cdk/interfaces/rds-config.js +7 -0
  60. package/dist/aws-cdk/interfaces/sqs-config.d.ts +145 -0
  61. package/dist/aws-cdk/interfaces/sqs-config.js +12 -0
  62. package/dist/aws-cdk/interfaces/tag-config.d.ts +18 -0
  63. package/dist/aws-cdk/interfaces/tag-config.js +2 -0
  64. package/dist/aws-cdk/interfaces/vpc-config.d.ts +72 -0
  65. package/dist/aws-cdk/interfaces/vpc-config.js +2 -0
  66. package/dist/aws-cdk/interfaces/waf-config.d.ts +180 -0
  67. package/dist/aws-cdk/interfaces/waf-config.js +2 -0
  68. package/dist/aws-cdk/utils/priority-tracker.d.ts +60 -0
  69. package/dist/aws-cdk/utils/priority-tracker.js +131 -0
  70. package/dist/index.d.ts +33 -0
  71. package/dist/index.js +55 -0
  72. package/dist/terraform-cdk/constructs/alb-listener-rule.d.ts +33 -0
  73. package/dist/terraform-cdk/constructs/alb-listener-rule.js +81 -0
  74. package/dist/terraform-cdk/constructs/ecs-service.d.ts +29 -0
  75. package/dist/terraform-cdk/constructs/ecs-service.js +238 -0
  76. package/dist/terraform-cdk/interfaces/ecs-service-config.d.ts +53 -0
  77. package/dist/terraform-cdk/interfaces/ecs-service-config.js +25 -0
  78. package/dist/terraform-cdk/interfaces/infrastructure-refs.d.ts +16 -0
  79. package/dist/terraform-cdk/interfaces/infrastructure-refs.js +8 -0
  80. package/dist/terraform-cdk/utils/priority-tracker.d.ts +60 -0
  81. package/dist/terraform-cdk/utils/priority-tracker.js +131 -0
  82. package/package.json +46 -0
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * ECS Service Configuration Interface
4
+ *
5
+ * Defines the configuration structure for creating ECS services with ALB integration.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ECS_SERVICE_DEFAULTS = void 0;
9
+ /**
10
+ * Default values for optional ECS service configuration
11
+ */
12
+ exports.ECS_SERVICE_DEFAULTS = {
13
+ healthCheckInterval: 30,
14
+ healthCheckTimeout: 5,
15
+ healthCheckHealthyThreshold: 2,
16
+ healthCheckUnhealthyThreshold: 3,
17
+ deregistrationDelay: 30,
18
+ targetGroupProtocol: 'HTTP',
19
+ logRetentionDays: 7,
20
+ enableAutoScaling: false,
21
+ minCapacity: 1,
22
+ maxCapacity: 10,
23
+ targetCpuUtilization: 70,
24
+ targetMemoryUtilization: 80,
25
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Infrastructure References Interface
3
+ *
4
+ * Defines the structure for referencing existing infrastructure resources
5
+ * from AWS CDK (unicorn-rx-0) to be used in Terraform CDK (banshee-rx-0)
6
+ */
7
+ export interface InfrastructureRefs {
8
+ vpcId: string;
9
+ privateSubnetIds: string[];
10
+ albListenerArn: string;
11
+ albSecurityGroupId: string;
12
+ ecsClusterName: string;
13
+ ecsClusterArn: string;
14
+ region: string;
15
+ accountId: string;
16
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Infrastructure References Interface
4
+ *
5
+ * Defines the structure for referencing existing infrastructure resources
6
+ * from AWS CDK (unicorn-rx-0) to be used in Terraform CDK (banshee-rx-0)
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Priority Tracker for ALB Listener Rules
3
+ *
4
+ * Manages priority assignments for ALB Listener Rules to prevent conflicts.
5
+ * Priorities must be unique within a listener (range: 1-50000).
6
+ */
7
+ export interface PriorityAssignment {
8
+ serviceName: string;
9
+ priority: number;
10
+ path?: string;
11
+ host?: string;
12
+ }
13
+ export declare class PriorityTracker {
14
+ private assignments;
15
+ private serviceNames;
16
+ /**
17
+ * Register a priority assignment
18
+ * @param serviceName Name of the ECS service
19
+ * @param priority Priority value (1-50000)
20
+ * @param path Optional path pattern
21
+ * @param host Optional host header
22
+ * @throws Error if priority is already assigned or out of range
23
+ */
24
+ registerPriority(serviceName: string, priority: number, path?: string, host?: string): void;
25
+ /**
26
+ * Get all priority assignments sorted by priority
27
+ * @returns Array of priority assignments
28
+ */
29
+ getAssignments(): PriorityAssignment[];
30
+ /**
31
+ * Check if a priority is available
32
+ * @param priority Priority value to check
33
+ * @returns True if priority is available
34
+ */
35
+ isPriorityAvailable(priority: number): boolean;
36
+ /**
37
+ * Get the next available priority
38
+ * @param startFrom Starting priority (default: 1)
39
+ * @returns Next available priority
40
+ */
41
+ getNextAvailablePriority(startFrom?: number): number;
42
+ /**
43
+ * Print a summary of all priority assignments
44
+ */
45
+ printSummary(): void;
46
+ /**
47
+ * Validate all assignments for conflicts
48
+ * @throws Error if conflicts are detected
49
+ */
50
+ validate(): void;
51
+ /**
52
+ * Clear all assignments
53
+ */
54
+ clear(): void;
55
+ /**
56
+ * Get total number of assignments
57
+ * @returns Number of registered assignments
58
+ */
59
+ get count(): number;
60
+ }
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /**
3
+ * Priority Tracker for ALB Listener Rules
4
+ *
5
+ * Manages priority assignments for ALB Listener Rules to prevent conflicts.
6
+ * Priorities must be unique within a listener (range: 1-50000).
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PriorityTracker = void 0;
10
+ class PriorityTracker {
11
+ constructor() {
12
+ this.assignments = new Map();
13
+ this.serviceNames = new Set();
14
+ }
15
+ /**
16
+ * Register a priority assignment
17
+ * @param serviceName Name of the ECS service
18
+ * @param priority Priority value (1-50000)
19
+ * @param path Optional path pattern
20
+ * @param host Optional host header
21
+ * @throws Error if priority is already assigned or out of range
22
+ */
23
+ registerPriority(serviceName, priority, path, host) {
24
+ // Validate priority range
25
+ if (priority < 1 || priority > 50000) {
26
+ throw new Error(`Invalid priority ${priority} for service ${serviceName}. Priority must be between 1 and 50000.`);
27
+ }
28
+ // Check for duplicate priority
29
+ if (this.assignments.has(priority)) {
30
+ const existing = this.assignments.get(priority);
31
+ throw new Error(`Priority conflict: Priority ${priority} is already assigned to service "${existing.serviceName}". ` +
32
+ `Cannot assign to service "${serviceName}".`);
33
+ }
34
+ // Check for duplicate service name
35
+ if (this.serviceNames.has(serviceName)) {
36
+ throw new Error(`Service name conflict: Service "${serviceName}" is already registered.`);
37
+ }
38
+ // Register the assignment
39
+ this.assignments.set(priority, {
40
+ serviceName,
41
+ priority,
42
+ path,
43
+ host,
44
+ });
45
+ this.serviceNames.add(serviceName);
46
+ }
47
+ /**
48
+ * Get all priority assignments sorted by priority
49
+ * @returns Array of priority assignments
50
+ */
51
+ getAssignments() {
52
+ return Array.from(this.assignments.values()).sort((a, b) => a.priority - b.priority);
53
+ }
54
+ /**
55
+ * Check if a priority is available
56
+ * @param priority Priority value to check
57
+ * @returns True if priority is available
58
+ */
59
+ isPriorityAvailable(priority) {
60
+ return !this.assignments.has(priority);
61
+ }
62
+ /**
63
+ * Get the next available priority
64
+ * @param startFrom Starting priority (default: 1)
65
+ * @returns Next available priority
66
+ */
67
+ getNextAvailablePriority(startFrom = 1) {
68
+ let priority = startFrom;
69
+ while (this.assignments.has(priority) && priority <= 50000) {
70
+ priority++;
71
+ }
72
+ if (priority > 50000) {
73
+ throw new Error('No available priorities. Maximum priority limit (50000) reached.');
74
+ }
75
+ return priority;
76
+ }
77
+ /**
78
+ * Print a summary of all priority assignments
79
+ */
80
+ printSummary() {
81
+ const assignments = this.getAssignments();
82
+ if (assignments.length === 0) {
83
+ console.log('\nšŸ“‹ Priority Tracker: No assignments registered\n');
84
+ return;
85
+ }
86
+ console.log('\nšŸ“‹ Priority Tracker Summary');
87
+ console.log('═══════════════════════════════════════════════════════════════');
88
+ console.log(`Total Services: ${assignments.length}`);
89
+ console.log('───────────────────────────────────────────────────────────────');
90
+ assignments.forEach((assignment) => {
91
+ const conditions = [];
92
+ if (assignment.path)
93
+ conditions.push(`Path: ${assignment.path}`);
94
+ if (assignment.host)
95
+ conditions.push(`Host: ${assignment.host}`);
96
+ const conditionStr = conditions.length > 0 ? ` (${conditions.join(', ')})` : '';
97
+ console.log(`Priority ${assignment.priority.toString().padStart(5)}: ${assignment.serviceName}${conditionStr}`);
98
+ });
99
+ console.log('═══════════════════════════════════════════════════════════════\n');
100
+ }
101
+ /**
102
+ * Validate all assignments for conflicts
103
+ * @throws Error if conflicts are detected
104
+ */
105
+ validate() {
106
+ const priorities = Array.from(this.assignments.keys());
107
+ const uniquePriorities = new Set(priorities);
108
+ if (priorities.length !== uniquePriorities.size) {
109
+ throw new Error('Priority conflict detected: Duplicate priorities found.');
110
+ }
111
+ const services = Array.from(this.serviceNames);
112
+ if (services.length !== this.assignments.size) {
113
+ throw new Error('Service name conflict detected: Duplicate service names found.');
114
+ }
115
+ }
116
+ /**
117
+ * Clear all assignments
118
+ */
119
+ clear() {
120
+ this.assignments.clear();
121
+ this.serviceNames.clear();
122
+ }
123
+ /**
124
+ * Get total number of assignments
125
+ * @returns Number of registered assignments
126
+ */
127
+ get count() {
128
+ return this.assignments.size;
129
+ }
130
+ }
131
+ exports.PriorityTracker = PriorityTracker;
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@dga-itc/aws-cdk-constructs",
3
+ "version": "1.0.0",
4
+ "description": "Reusable AWS infrastructure constructs for AWS CDK",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "jest --passWithNoTests",
10
+ "prepublishOnly": "npm run build"
11
+ },
12
+ "keywords": [
13
+ "aws",
14
+ "cdk",
15
+ "infrastructure",
16
+ "constructs",
17
+ "vpc",
18
+ "alb",
19
+ "nlb",
20
+ "ecs",
21
+ "rds",
22
+ "elasticache",
23
+ "efs",
24
+ "acm",
25
+ "cloudfront",
26
+ "sqs",
27
+ "waf"
28
+ ],
29
+ "author": "DGA-ITC",
30
+ "license": "MIT",
31
+ "peerDependencies": {
32
+ "aws-cdk-lib": "^2.0.0",
33
+ "constructs": "^10.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^20.0.0",
37
+ "typescript": "^5.0.0",
38
+ "jest": "^29.0.0",
39
+ "@types/jest": "^29.0.0",
40
+ "ts-jest": "^29.0.0"
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "README.md"
45
+ ]
46
+ }