@certenza/aws-cdk-infrastructure-commons 1.1.1 → 1.1.2

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.
@@ -67,6 +67,11 @@ 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 access log group
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
75
  const api = new apigateway.RestApi(scope, apiName, {
71
76
  description: `Public API Gateway for ${apiName}`,
72
77
  endpointTypes: [apigateway.EndpointType.REGIONAL],
@@ -76,24 +81,37 @@ const createApiGateway = (scope, apiName, domainName, hostedZoneId, zoneName) =>
76
81
  securityPolicy: apigateway.SecurityPolicy.TLS_1_2,
77
82
  endpointType: apigateway.EndpointType.REGIONAL,
78
83
  },
79
- deployOptions: {
80
- loggingLevel: apigateway.MethodLoggingLevel.INFO,
81
- dataTraceEnabled: false,
82
- accessLogDestination: new apigateway.LogGroupLogDestination(new logs.LogGroup(scope, `${apiName}-AccessLogs`, {
83
- retention: logs.RetentionDays.ONE_WEEK,
84
- })),
85
- },
84
+ deploy: false, // Don't auto-deploy - we'll create deployment and stage manually
86
85
  });
87
- // Set retention for execution log group that API Gateway creates automatically
86
+ // Create execution log group with the exact name API Gateway expects
88
87
  // API Gateway creates execution logs in the format: API-Gateway-Execution-Logs_{api-id}/{stage-name}
89
- // We use LogRetention to set the retention policy after API Gateway creates the log group
90
- new logs.LogRetention(scope, `${apiName}-ExecutionLogRetention`, {
88
+ // By creating it first, API Gateway will use our log group instead of creating a new one
89
+ const executionLogGroup = new logs.LogGroup(scope, `${apiName}-ExecutionLogs`, {
91
90
  logGroupName: cdk.Token.asString(cdk.Fn.join("/", [
92
- cdk.Fn.join("_", ["API-Gateway-Execution-Logs", api.restApiId]),
93
- api.deploymentStage.stageName,
91
+ cdk.Fn.join("_", [
92
+ "API-Gateway-Execution-Logs",
93
+ api.restApiId,
94
+ ]),
95
+ "prod", // Default stage name
94
96
  ])),
95
97
  retention: logs.RetentionDays.ONE_MONTH, // Budget-friendly: 1 month retention
98
+ removalPolicy: cdk.RemovalPolicy.DESTROY, // Retain log group even if API is deleted
99
+ });
100
+ // Create deployment
101
+ const deployment = new apigateway.Deployment(scope, `${apiName}-Deployment`, {
102
+ api: api,
103
+ });
104
+ // Create stage with logging configuration
105
+ // The execution log group must exist before the stage is created
106
+ const stage = new apigateway.Stage(scope, `${apiName}-Stage`, {
107
+ deployment: deployment,
108
+ stageName: "prod",
109
+ loggingLevel: apigateway.MethodLoggingLevel.INFO,
110
+ dataTraceEnabled: false,
111
+ accessLogDestination: new apigateway.LogGroupLogDestination(accessLogGroup),
96
112
  });
113
+ // Ensure the execution log group is created before the stage
114
+ stage.node.addDependency(executionLogGroup);
97
115
  // Create Route53 A record pointing to the API Gateway
98
116
  new route53.ARecord(scope, `${apiName}-AliasRecord`, {
99
117
  zone: hostedZone,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certenza/aws-cdk-infrastructure-commons",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
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",