@certenza/aws-cdk-infrastructure-commons 2.0.1 → 2.0.3
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 +17 -67
- package/package.json +1 -1
package/dist/src/apigateway.js
CHANGED
|
@@ -67,80 +67,30 @@ const createApiGateway = (scope, apiName, domainName, hostedZoneId, zoneName) =>
|
|
|
67
67
|
const hostedZone = (0, route53_1.getHostedZone)(scope, "HostedZone", hostedZoneId, zoneName);
|
|
68
68
|
// Create a certificate for the API Gateway domain
|
|
69
69
|
const certificate = (0, acm_1.createCertificate)(scope, `ApiGatewayCertificate`, domainName, hostedZone);
|
|
70
|
-
// Create
|
|
71
|
-
const accessLogGroup = new logs.LogGroup(scope, `${apiName}-AccessLogs`, {
|
|
72
|
-
retention: logs.RetentionDays.ONE_WEEK,
|
|
73
|
-
});
|
|
74
|
-
// Create RestApi without auto-deployment so we can control the order of resource creation
|
|
70
|
+
// Create the API Gateway
|
|
75
71
|
const api = new apigateway.RestApi(scope, apiName, {
|
|
76
72
|
description: `Public API Gateway for ${apiName}`,
|
|
77
73
|
endpointTypes: [apigateway.EndpointType.REGIONAL],
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
])),
|
|
93
|
-
retention: logs.RetentionDays.ONE_MONTH, // Budget-friendly: 1 month retention
|
|
94
|
-
removalPolicy: cdk.RemovalPolicy.DESTROY, // Destroy log group when API is deleted
|
|
95
|
-
});
|
|
96
|
-
// Create deployment that automatically updates when API changes
|
|
97
|
-
// The Deployment construct should automatically detect when the API definition changes
|
|
98
|
-
// and create a new deployment. The dependency on api.root helps ensure this works.
|
|
99
|
-
// Note: If you add methods/resources and the stage doesn't update, the deployment
|
|
100
|
-
// might not be detecting changes. In that case, you may need to manually trigger
|
|
101
|
-
// a redeployment or use a hash-based approach.
|
|
102
|
-
const deployment = new apigateway.Deployment(scope, `${apiName}-Deployment`, {
|
|
103
|
-
api: api,
|
|
104
|
-
retainDeployments: false,
|
|
105
|
-
});
|
|
106
|
-
// Add dependency on API root to help ensure deployment updates when API changes
|
|
107
|
-
// This dependency ensures the deployment is recreated when methods/resources are added
|
|
108
|
-
deployment.node.addDependency(api.root);
|
|
109
|
-
// Create stage with logging configuration
|
|
110
|
-
// The execution log group must exist before the stage is created so API Gateway uses it
|
|
111
|
-
const stage = new apigateway.Stage(scope, `${apiName}-Stage`, {
|
|
112
|
-
deployment: deployment,
|
|
113
|
-
stageName: "prod",
|
|
114
|
-
loggingLevel: apigateway.MethodLoggingLevel.INFO,
|
|
115
|
-
dataTraceEnabled: false,
|
|
116
|
-
accessLogDestination: new apigateway.LogGroupLogDestination(accessLogGroup),
|
|
117
|
-
});
|
|
118
|
-
// Ensure the execution log group is created before the stage
|
|
119
|
-
// This is necessary because the stage doesn't reference the log group directly,
|
|
120
|
-
// but API Gateway needs it to exist when the stage is created
|
|
121
|
-
stage.node.addDependency(executionLogGroup);
|
|
122
|
-
// Create custom domain name with TLS 1.2 security policy
|
|
123
|
-
// CDK automatically ensures the certificate is validated before creating the domain
|
|
124
|
-
const apiDomain = new apigateway.DomainName(scope, `${apiName}-Domain`, {
|
|
125
|
-
domainName: domainName,
|
|
126
|
-
certificate: certificate,
|
|
127
|
-
securityPolicy: apigateway.SecurityPolicy.TLS_1_2, // Enforce TLS 1.2 minimum
|
|
128
|
-
endpointType: apigateway.EndpointType.REGIONAL,
|
|
129
|
-
});
|
|
130
|
-
// Map the custom domain to the API stage
|
|
131
|
-
// CDK automatically handles dependencies: BasePathMapping depends on apiDomain, api, and stage
|
|
132
|
-
new apigateway.BasePathMapping(scope, `${apiName}-BasePathMapping`, {
|
|
133
|
-
domainName: apiDomain,
|
|
134
|
-
restApi: api,
|
|
135
|
-
stage: stage,
|
|
74
|
+
domainName: {
|
|
75
|
+
domainName: domainName,
|
|
76
|
+
certificate: certificate,
|
|
77
|
+
securityPolicy: apigateway.SecurityPolicy.TLS_1_2,
|
|
78
|
+
endpointType: apigateway.EndpointType.REGIONAL,
|
|
79
|
+
},
|
|
80
|
+
deployOptions: {
|
|
81
|
+
loggingLevel: apigateway.MethodLoggingLevel.OFF,
|
|
82
|
+
dataTraceEnabled: false,
|
|
83
|
+
accessLogDestination: new apigateway.LogGroupLogDestination(new logs.LogGroup(scope, `${apiName}-AccessLogs`, {
|
|
84
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
85
|
+
retention: logs.RetentionDays.ONE_WEEK,
|
|
86
|
+
})),
|
|
87
|
+
},
|
|
136
88
|
});
|
|
137
|
-
// Create Route53 A record pointing to the API Gateway
|
|
138
|
-
// CDK automatically handles dependency: Route53 record waits for domain to be created
|
|
139
|
-
// via the alias target (ApiGatewayDomain)
|
|
89
|
+
// Create Route53 A record pointing to the API Gateway
|
|
140
90
|
new route53.ARecord(scope, `${apiName}-AliasRecord`, {
|
|
141
91
|
zone: hostedZone,
|
|
142
92
|
recordName: domainName.replace(`${hostedZone.zoneName}.`, ""),
|
|
143
|
-
target: route53.RecordTarget.fromAlias(new route53targets.
|
|
93
|
+
target: route53.RecordTarget.fromAlias(new route53targets.ApiGateway(api)),
|
|
144
94
|
});
|
|
145
95
|
// Return the API Gateway
|
|
146
96
|
return api;
|
package/package.json
CHANGED