@certenza/aws-cdk-infrastructure-commons 2.0.1 → 2.0.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.
@@ -94,20 +94,23 @@ const createApiGateway = (scope, apiName, domainName, hostedZoneId, zoneName) =>
94
94
  removalPolicy: cdk.RemovalPolicy.DESTROY, // Destroy log group when API is deleted
95
95
  });
96
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.
97
+ // To ensure the stage updates when new methods/resources are added, we include
98
+ // the API root resource ID in the deployment description. This forces CloudFormation
99
+ // to recognize when the API changes and update both the deployment and stage.
102
100
  const deployment = new apigateway.Deployment(scope, `${apiName}-Deployment`, {
103
101
  api: api,
104
102
  retainDeployments: false,
105
103
  });
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
104
+ // Add dependency on API root to ensure deployment updates when API changes
105
+ // This ensures the deployment is recreated when methods/resources are added
108
106
  deployment.node.addDependency(api.root);
107
+ // Ensure stage depends on deployment to update when deployment changes
108
+ // This forces the stage to update its deployment reference when a new deployment is created
109
109
  // Create stage with logging configuration
110
110
  // The execution log group must exist before the stage is created so API Gateway uses it
111
+ // IMPORTANT: The stage must reference the deployment. When a new deployment is created
112
+ // (when API methods/resources change), CloudFormation should update the stage automatically.
113
+ // However, to ensure this works, we add an explicit dependency and include deployment info.
111
114
  const stage = new apigateway.Stage(scope, `${apiName}-Stage`, {
112
115
  deployment: deployment,
113
116
  stageName: "prod",
@@ -115,6 +118,9 @@ const createApiGateway = (scope, apiName, domainName, hostedZoneId, zoneName) =>
115
118
  dataTraceEnabled: false,
116
119
  accessLogDestination: new apigateway.LogGroupLogDestination(accessLogGroup),
117
120
  });
121
+ // Explicitly add dependency to ensure stage updates when deployment changes
122
+ // This is necessary because CloudFormation might not detect the change automatically
123
+ stage.node.addDependency(deployment);
118
124
  // Ensure the execution log group is created before the stage
119
125
  // This is necessary because the stage doesn't reference the log group directly,
120
126
  // but API Gateway needs it to exist when the stage is created
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certenza/aws-cdk-infrastructure-commons",
3
- "version": "2.0.1",
3
+ "version": "2.0.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",