@certenza/aws-cdk-infrastructure-commons 1.1.2 → 2.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/dist/src/apigateway.js +25 -10
- package/dist/src/lambda.js +2 -2
- package/package.json +5 -5
package/dist/src/apigateway.js
CHANGED
|
@@ -75,17 +75,13 @@ const createApiGateway = (scope, apiName, domainName, hostedZoneId, zoneName) =>
|
|
|
75
75
|
const api = new apigateway.RestApi(scope, apiName, {
|
|
76
76
|
description: `Public API Gateway for ${apiName}`,
|
|
77
77
|
endpointTypes: [apigateway.EndpointType.REGIONAL],
|
|
78
|
-
domainName: {
|
|
79
|
-
domainName: domainName,
|
|
80
|
-
certificate: certificate,
|
|
81
|
-
securityPolicy: apigateway.SecurityPolicy.TLS_1_2,
|
|
82
|
-
endpointType: apigateway.EndpointType.REGIONAL,
|
|
83
|
-
},
|
|
84
78
|
deploy: false, // Don't auto-deploy - we'll create deployment and stage manually
|
|
85
79
|
});
|
|
86
80
|
// Create execution log group with the exact name API Gateway expects
|
|
87
81
|
// API Gateway creates execution logs in the format: API-Gateway-Execution-Logs_{api-id}/{stage-name}
|
|
88
82
|
// By creating it first, API Gateway will use our log group instead of creating a new one
|
|
83
|
+
// Note: The log group name depends on api.restApiId (a token), so CloudFormation will
|
|
84
|
+
// create the API first to resolve the token, then create the log group with the resolved name
|
|
89
85
|
const executionLogGroup = new logs.LogGroup(scope, `${apiName}-ExecutionLogs`, {
|
|
90
86
|
logGroupName: cdk.Token.asString(cdk.Fn.join("/", [
|
|
91
87
|
cdk.Fn.join("_", [
|
|
@@ -95,14 +91,14 @@ const createApiGateway = (scope, apiName, domainName, hostedZoneId, zoneName) =>
|
|
|
95
91
|
"prod", // Default stage name
|
|
96
92
|
])),
|
|
97
93
|
retention: logs.RetentionDays.ONE_MONTH, // Budget-friendly: 1 month retention
|
|
98
|
-
removalPolicy: cdk.RemovalPolicy.DESTROY, //
|
|
94
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY, // Destroy log group when API is deleted
|
|
99
95
|
});
|
|
100
96
|
// Create deployment
|
|
101
97
|
const deployment = new apigateway.Deployment(scope, `${apiName}-Deployment`, {
|
|
102
98
|
api: api,
|
|
103
99
|
});
|
|
104
100
|
// Create stage with logging configuration
|
|
105
|
-
// The execution log group must exist before the stage is created
|
|
101
|
+
// The execution log group must exist before the stage is created so API Gateway uses it
|
|
106
102
|
const stage = new apigateway.Stage(scope, `${apiName}-Stage`, {
|
|
107
103
|
deployment: deployment,
|
|
108
104
|
stageName: "prod",
|
|
@@ -111,12 +107,31 @@ const createApiGateway = (scope, apiName, domainName, hostedZoneId, zoneName) =>
|
|
|
111
107
|
accessLogDestination: new apigateway.LogGroupLogDestination(accessLogGroup),
|
|
112
108
|
});
|
|
113
109
|
// Ensure the execution log group is created before the stage
|
|
110
|
+
// This is necessary because the stage doesn't reference the log group directly,
|
|
111
|
+
// but API Gateway needs it to exist when the stage is created
|
|
114
112
|
stage.node.addDependency(executionLogGroup);
|
|
115
|
-
// Create
|
|
113
|
+
// Create custom domain name with TLS 1.2 security policy
|
|
114
|
+
// CDK automatically ensures the certificate is validated before creating the domain
|
|
115
|
+
const apiDomain = new apigateway.DomainName(scope, `${apiName}-Domain`, {
|
|
116
|
+
domainName: domainName,
|
|
117
|
+
certificate: certificate,
|
|
118
|
+
securityPolicy: apigateway.SecurityPolicy.TLS_1_2, // Enforce TLS 1.2 minimum
|
|
119
|
+
endpointType: apigateway.EndpointType.REGIONAL,
|
|
120
|
+
});
|
|
121
|
+
// Map the custom domain to the API stage
|
|
122
|
+
// CDK automatically handles dependencies: BasePathMapping depends on apiDomain, api, and stage
|
|
123
|
+
new apigateway.BasePathMapping(scope, `${apiName}-BasePathMapping`, {
|
|
124
|
+
domainName: apiDomain,
|
|
125
|
+
restApi: api,
|
|
126
|
+
stage: stage,
|
|
127
|
+
});
|
|
128
|
+
// Create Route53 A record pointing to the API Gateway custom domain
|
|
129
|
+
// CDK automatically handles dependency: Route53 record waits for domain to be created
|
|
130
|
+
// via the alias target (ApiGatewayDomain)
|
|
116
131
|
new route53.ARecord(scope, `${apiName}-AliasRecord`, {
|
|
117
132
|
zone: hostedZone,
|
|
118
133
|
recordName: domainName.replace(`${hostedZone.zoneName}.`, ""),
|
|
119
|
-
target: route53.RecordTarget.fromAlias(new route53targets.
|
|
134
|
+
target: route53.RecordTarget.fromAlias(new route53targets.ApiGatewayDomain(apiDomain)),
|
|
120
135
|
});
|
|
121
136
|
// Return the API Gateway
|
|
122
137
|
return api;
|
package/dist/src/lambda.js
CHANGED
|
@@ -64,7 +64,7 @@ const createLambdaFunction = (scope, functionName, environment, props = {}) => {
|
|
|
64
64
|
entry: `src/lambdas/${functionName}/handler.ts`,
|
|
65
65
|
functionName: functionName,
|
|
66
66
|
handler: "handler",
|
|
67
|
-
runtime: lambda.Runtime.
|
|
67
|
+
runtime: lambda.Runtime.NODEJS_24_X,
|
|
68
68
|
architecture: lambda.Architecture.ARM_64,
|
|
69
69
|
memorySize: 256,
|
|
70
70
|
timeout: cdk.Duration.seconds(30),
|
|
@@ -76,7 +76,7 @@ const createLambdaFunction = (scope, functionName, environment, props = {}) => {
|
|
|
76
76
|
bundling: {
|
|
77
77
|
minify: true,
|
|
78
78
|
sourceMap: false,
|
|
79
|
-
target: "
|
|
79
|
+
target: "es2024",
|
|
80
80
|
format: nodejs.OutputFormat.CJS,
|
|
81
81
|
mainFields: ["module", "main"],
|
|
82
82
|
externalModules: ["aws-sdk", "util", "crypto", "stream"], // AWS SDK is provided by Lambda runtime
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@certenza/aws-cdk-infrastructure-commons",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Common infrastructure reusable utilities and resources for Certenza projects",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/certenza/aws-cdk-infrastructure-commons#readme",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"aws-cdk-lib": "^2.
|
|
39
|
+
"aws-cdk-lib": "^2.230.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/node": "^
|
|
43
|
-
"prettier": "^3.
|
|
42
|
+
"@types/node": "^24.0.0",
|
|
43
|
+
"prettier": "^3.7.2",
|
|
44
44
|
"rimraf": "^6.1.2",
|
|
45
45
|
"typescript": "^5.9.3"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": ">=24.0.0"
|
|
49
49
|
}
|
|
50
50
|
}
|