@certenza/aws-cdk-infrastructure-commons 1.1.0 → 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,23 +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
- // Create execution log group with 1-month retention
88
- // We need to create this log group explicitly to set retention
89
- // The log group name uses tokens that will be resolved at deployment time
86
+ // Create execution log group with the exact name API Gateway expects
87
+ // API Gateway creates execution logs in the format: API-Gateway-Execution-Logs_{api-id}/{stage-name}
88
+ // By creating it first, API Gateway will use our log group instead of creating a new one
90
89
  const executionLogGroup = new logs.LogGroup(scope, `${apiName}-ExecutionLogs`, {
90
+ logGroupName: cdk.Token.asString(cdk.Fn.join("/", [
91
+ cdk.Fn.join("_", [
92
+ "API-Gateway-Execution-Logs",
93
+ api.restApiId,
94
+ ]),
95
+ "prod", // Default stage name
96
+ ])),
91
97
  retention: logs.RetentionDays.ONE_MONTH, // Budget-friendly: 1 month retention
92
- removalPolicy: cdk.RemovalPolicy.DESTROY,
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),
93
112
  });
94
- // Ensure the log group is created after the API
95
- executionLogGroup.node.addDependency(api);
113
+ // Ensure the execution log group is created before the stage
114
+ stage.node.addDependency(executionLogGroup);
96
115
  // Create Route53 A record pointing to the API Gateway
97
116
  new route53.ARecord(scope, `${apiName}-AliasRecord`, {
98
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.0",
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",