@aetherionfw/infra 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.
- package/LICENSE +21 -0
- package/dist/builder/FrameworkStack.d.ts +5 -0
- package/dist/builder/FrameworkStack.js +203 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +7 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cristian Londoño
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FrameworkStack = void 0;
|
|
4
|
+
const cdktf_1 = require("cdktf");
|
|
5
|
+
const provider_1 = require("@cdktf/provider-aws/lib/provider");
|
|
6
|
+
const s3_bucket_1 = require("@cdktf/provider-aws/lib/s3-bucket");
|
|
7
|
+
const dynamodb_table_1 = require("@cdktf/provider-aws/lib/dynamodb-table");
|
|
8
|
+
const sqs_queue_1 = require("@cdktf/provider-aws/lib/sqs-queue");
|
|
9
|
+
const kms_key_1 = require("@cdktf/provider-aws/lib/kms-key");
|
|
10
|
+
const ssm_parameter_1 = require("@cdktf/provider-aws/lib/ssm-parameter");
|
|
11
|
+
const cloudfront_distribution_1 = require("@cdktf/provider-aws/lib/cloudfront-distribution");
|
|
12
|
+
const cognito_user_pool_1 = require("@cdktf/provider-aws/lib/cognito-user-pool");
|
|
13
|
+
const vpc_1 = require("@cdktf/provider-aws/lib/vpc");
|
|
14
|
+
const iam_role_1 = require("@cdktf/provider-aws/lib/iam-role");
|
|
15
|
+
const iam_role_policy_1 = require("@cdktf/provider-aws/lib/iam-role-policy");
|
|
16
|
+
const db_instance_1 = require("@cdktf/provider-aws/lib/db-instance");
|
|
17
|
+
const lambda_function_1 = require("@cdktf/provider-aws/lib/lambda-function");
|
|
18
|
+
const lambda_event_source_mapping_1 = require("@cdktf/provider-aws/lib/lambda-event-source-mapping");
|
|
19
|
+
const core_1 = require("@aetherionfw/core");
|
|
20
|
+
class FrameworkStack extends cdktf_1.TerraformStack {
|
|
21
|
+
constructor(scope, id) {
|
|
22
|
+
super(scope, id);
|
|
23
|
+
new provider_1.AwsProvider(this, 'AWS', {
|
|
24
|
+
region: 'us-east-1',
|
|
25
|
+
});
|
|
26
|
+
const registry = core_1.MetadataRegistry.getInstance();
|
|
27
|
+
// 1. Build Infra Resources
|
|
28
|
+
const infraClasses = registry.getInfraClasses();
|
|
29
|
+
for (const target of infraClasses) {
|
|
30
|
+
const resources = registry.getInfraResources(target);
|
|
31
|
+
for (const res of resources) {
|
|
32
|
+
console.log(`Building ${res.type}: ${res.name}`);
|
|
33
|
+
switch (res.type) {
|
|
34
|
+
case 'S3Bucket':
|
|
35
|
+
new s3_bucket_1.S3Bucket(this, res.name, {
|
|
36
|
+
bucket: res.props.name,
|
|
37
|
+
// Minimal abstracted configuration mapped to raw CDKTF
|
|
38
|
+
});
|
|
39
|
+
break;
|
|
40
|
+
case 'DynamoTable':
|
|
41
|
+
new dynamodb_table_1.DynamodbTable(this, res.name, {
|
|
42
|
+
name: res.props.name,
|
|
43
|
+
hashKey: res.props.partitionKey.name,
|
|
44
|
+
attribute: [{ name: res.props.partitionKey.name, type: res.props.partitionKey.type === 'STRING' ? 'S' : 'N' }],
|
|
45
|
+
billingMode: 'PAY_PER_REQUEST',
|
|
46
|
+
});
|
|
47
|
+
break;
|
|
48
|
+
case 'SqsQueue':
|
|
49
|
+
new sqs_queue_1.SqsQueue(this, res.name, {
|
|
50
|
+
name: res.props.name,
|
|
51
|
+
visibilityTimeoutSeconds: res.props.visibilityTimeout,
|
|
52
|
+
});
|
|
53
|
+
break;
|
|
54
|
+
case 'KmsKey':
|
|
55
|
+
new kms_key_1.KmsKey(this, res.name, {
|
|
56
|
+
description: res.props.description,
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
case 'SsmParameter':
|
|
60
|
+
new ssm_parameter_1.SsmParameter(this, res.name, {
|
|
61
|
+
name: res.props.name,
|
|
62
|
+
type: res.props.type || 'String',
|
|
63
|
+
value: res.props.value,
|
|
64
|
+
});
|
|
65
|
+
break;
|
|
66
|
+
case 'CloudFrontDistribution':
|
|
67
|
+
// Simplified mapping for a highly complex resource
|
|
68
|
+
new cloudfront_distribution_1.CloudfrontDistribution(this, res.name, {
|
|
69
|
+
enabled: true,
|
|
70
|
+
origin: [{
|
|
71
|
+
domainName: res.props.originDomain,
|
|
72
|
+
originId: `${res.name}-origin`,
|
|
73
|
+
}],
|
|
74
|
+
defaultCacheBehavior: {
|
|
75
|
+
targetOriginId: `${res.name}-origin`,
|
|
76
|
+
viewerProtocolPolicy: 'redirect-to-https',
|
|
77
|
+
allowedMethods: ['GET', 'HEAD', 'OPTIONS'],
|
|
78
|
+
cachedMethods: ['GET', 'HEAD', 'OPTIONS'],
|
|
79
|
+
},
|
|
80
|
+
viewerCertificate: {
|
|
81
|
+
cloudfrontDefaultCertificate: true,
|
|
82
|
+
},
|
|
83
|
+
restrictions: { geoRestriction: { restrictionType: 'none' } },
|
|
84
|
+
});
|
|
85
|
+
break;
|
|
86
|
+
case 'CognitoUserPool':
|
|
87
|
+
new cognito_user_pool_1.CognitoUserPool(this, res.name, {
|
|
88
|
+
name: res.props.name,
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
case 'Vpc':
|
|
92
|
+
new vpc_1.Vpc(this, res.name, {
|
|
93
|
+
cidrBlock: res.props.cidr,
|
|
94
|
+
enableDnsSupport: true,
|
|
95
|
+
enableDnsHostnames: true,
|
|
96
|
+
tags: { Name: res.props.name },
|
|
97
|
+
});
|
|
98
|
+
break;
|
|
99
|
+
case 'IamRole':
|
|
100
|
+
new iam_role_1.IamRole(this, res.name, {
|
|
101
|
+
name: res.props.name,
|
|
102
|
+
assumeRolePolicy: res.props.assumedBy, // Assume this is a JSON string passed in
|
|
103
|
+
});
|
|
104
|
+
break;
|
|
105
|
+
case 'RdsInstance':
|
|
106
|
+
new db_instance_1.DbInstance(this, res.name, {
|
|
107
|
+
engine: res.props.engine,
|
|
108
|
+
instanceClass: res.props.size,
|
|
109
|
+
dbName: res.props.dbName,
|
|
110
|
+
skipFinalSnapshot: true, // safe default for dev frameworks
|
|
111
|
+
});
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
console.warn(`Unknown infra resource type: ${res.type}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// 2. Build Lambdas and IAM Policies (1:1 Lambda per Handle Architecture)
|
|
119
|
+
const controllers = registry.getControllers();
|
|
120
|
+
for (const [target, controllerMeta] of controllers) {
|
|
121
|
+
const handles = registry.getHandles(target);
|
|
122
|
+
const iamPermissions = registry.getIamPermissions(target);
|
|
123
|
+
const routes = registry.getRoutes(target);
|
|
124
|
+
const sqsTriggers = registry.getSqsTriggers(target);
|
|
125
|
+
if (handles.length === 0) {
|
|
126
|
+
// Fallback or skip if no methods are decorated with @Handle
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
for (const handle of handles) {
|
|
130
|
+
const methodName = handle.methodName;
|
|
131
|
+
const lambdaName = `${controllerMeta.lambdaName}-${methodName}`;
|
|
132
|
+
console.log(`Building 1:1 Lambda: ${lambdaName}`);
|
|
133
|
+
// 2a. Create Execution Role for this specific Lambda
|
|
134
|
+
const role = new iam_role_1.IamRole(this, `${lambdaName}-role`, {
|
|
135
|
+
name: `${lambdaName}-role`,
|
|
136
|
+
assumeRolePolicy: JSON.stringify({
|
|
137
|
+
Version: "2012-10-17",
|
|
138
|
+
Statement: [{
|
|
139
|
+
Action: "sts:AssumeRole",
|
|
140
|
+
Principal: { Service: "lambda.amazonaws.com" },
|
|
141
|
+
Effect: "Allow",
|
|
142
|
+
}],
|
|
143
|
+
}),
|
|
144
|
+
});
|
|
145
|
+
// 2b. Attach IAM Policies (Method overrides Class)
|
|
146
|
+
let handlePerms = iamPermissions.find(p => p.methodName === methodName);
|
|
147
|
+
if (!handlePerms) {
|
|
148
|
+
// Fallback to class-level permissions
|
|
149
|
+
handlePerms = iamPermissions.find(p => !p.methodName);
|
|
150
|
+
}
|
|
151
|
+
if (handlePerms) {
|
|
152
|
+
const statements = [];
|
|
153
|
+
for (const service of Object.keys(handlePerms.permissions)) {
|
|
154
|
+
const rules = handlePerms.permissions[service];
|
|
155
|
+
for (const rule of rules) {
|
|
156
|
+
statements.push({
|
|
157
|
+
Effect: "Allow",
|
|
158
|
+
Action: rule.action,
|
|
159
|
+
Resource: rule.resource,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (statements.length > 0) {
|
|
164
|
+
new iam_role_policy_1.IamRolePolicy(this, `${lambdaName}-policy`, {
|
|
165
|
+
name: `${lambdaName}-inline-policy`,
|
|
166
|
+
role: role.name,
|
|
167
|
+
policy: JSON.stringify({
|
|
168
|
+
Version: "2012-10-17",
|
|
169
|
+
Statement: statements,
|
|
170
|
+
}),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// 2c. Create the Lambda Function
|
|
175
|
+
const lambdaFunction = new lambda_function_1.LambdaFunction(this, lambdaName, {
|
|
176
|
+
functionName: lambdaName,
|
|
177
|
+
runtime: controllerMeta.runtime || 'nodejs20.x',
|
|
178
|
+
memorySize: handle.memorySize || controllerMeta.memorySize || 128,
|
|
179
|
+
timeout: handle.timeout || controllerMeta.timeout || 3,
|
|
180
|
+
role: role.arn,
|
|
181
|
+
filename: 'dummy.zip', // CDKTF requires a deployment package
|
|
182
|
+
handler: 'index.handler',
|
|
183
|
+
environment: {
|
|
184
|
+
variables: {
|
|
185
|
+
AETHERION_TARGET_CLASS: controllerMeta.lambdaName, // Storing for debug
|
|
186
|
+
AETHERION_TARGET_METHOD: methodName,
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
// 2d. Check for SQS Triggers targeting this handle
|
|
191
|
+
const handleTriggers = sqsTriggers.filter(t => t.methodName === methodName);
|
|
192
|
+
for (const trigger of handleTriggers) {
|
|
193
|
+
console.log(`Linking SQS Trigger ${trigger.queueName} to ${lambdaName}`);
|
|
194
|
+
new lambda_event_source_mapping_1.LambdaEventSourceMapping(this, `${lambdaName}-${trigger.queueName}-mapping`, {
|
|
195
|
+
functionName: lambdaFunction.arn,
|
|
196
|
+
eventSourceArn: `arn:aws:sqs:us-east-1:123456789012:${trigger.queueName}`, // mock
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.FrameworkStack = FrameworkStack;
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cdktf_1 = require("cdktf");
|
|
4
|
+
const FrameworkStack_1 = require("./builder/FrameworkStack");
|
|
5
|
+
const app = new cdktf_1.App();
|
|
6
|
+
new FrameworkStack_1.FrameworkStack(app, 'aetherion-dev');
|
|
7
|
+
app.synth();
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aetherionfw/infra",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CDKTF Builder for Aetherion Framework",
|
|
5
|
+
"main": "dist/main.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"cdktf": "^0.20.0",
|
|
8
|
+
"constructs": "^10.3.0",
|
|
9
|
+
"@cdktf/provider-aws": "^19.0.0",
|
|
10
|
+
"@aetherionfw/core": "1.0.0"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"typescript": "^5.5.4"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"package.json",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"author": "CrisD3v",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"synth": "cdktf synth",
|
|
28
|
+
"deploy": "cdktf deploy",
|
|
29
|
+
"clean": "rm -rf dist cdktf.out"
|
|
30
|
+
}
|
|
31
|
+
}
|