You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When cloudWatchRole is enabled, a CfnAccount is created for it. Since there is no explicit dependency between the the stages and the account, CloudFormation may deploy them in the wrong order, causing the deployment to fail.
Add an explicit dependency between Stages (whether defined by the user or created automatically) and the CloudWatch CfnAccount, if it exists.
This PR solved it for the RestApi #18011 but not entirely for the SpecRestApi.
Currently when we instantiate a SpecRestApi the class will first create the Deployment and the Stage
The problem is that when calling the _attachStage the cloudwatchAccount does not exist yet, so it does not create the dependency between each other (as in RestApi)
arnulfojr
changed the title
(aws-apigateway): race condition between Stage and CfnAccount
(aws-apigateway): race condition between Stage and CfnAccount on SpecRestApi
Feb 10, 2022
…n specrestapi (#22671)
This PR is based off of #18011, which fixed a race condition between RestApi stages and CloudWatch roles. The mentioned PR fixed the issue for RestApi, but not SpecRestApi, which this PR aims to fix.
The fix was largely implemented in RestApiBase. Since SpecRestApi inherits the same RestApiBase as RestApi, all we need to do is swap the order of resource creation so that the CloudWatch role is created before the RestApi stage, and can be attached correctly.
This PR also updates the integration tests to reflect the new dependency RestApi stage has on RestApi account.
Fixes#18925
### All Submissions:
* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
What is the problem?
When cloudWatchRole is enabled, a CfnAccount is created for it. Since there is no explicit dependency between the the stages and the account, CloudFormation may deploy them in the wrong order, causing the deployment to fail.
Add an explicit dependency between Stages (whether defined by the user or created automatically) and the CloudWatch CfnAccount, if it exists.
This PR solved it for the RestApi #18011 but not entirely for the SpecRestApi.
Currently when we instantiate a SpecRestApi the class will first create the Deployment and the Stage
aws-cdk/packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Lines 651 to 660 in 5dd8e50
then attach the Stage to the API
aws-cdk/packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Lines 560 to 565 in 5dd8e50
The problem is that when calling the
_attachStage
the cloudwatchAccount does not exist yet, so it does not create the dependency between each other (as in RestApi)aws-cdk/packages/@aws-cdk/aws-apigateway/lib/stage.ts
Lines 258 to 263 in 5dd8e50
If my understanding is correct, we would just need to swap the calls, first create the cloudwatchAccount then create the deployment and stage.
Reproduction Steps
Create a SpecRestApi and deploy the stack all at once.
What did you expect to happen?
Deployment to complete.
What actually happened?
When creating a SpecRestApi the race condition still happens
CDK CLI Version
1.142.0 (build 5dd8e50)
Framework Version
1.142.0
Node.js Version
17.3.0
OS
macOS
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: