Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(apigateway): race condition exists between stage and cfnaccount in specrestapi #22671

Merged
merged 5 commits into from Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Expand Up @@ -662,16 +662,16 @@ export class SpecRestApi extends RestApiBase {
this.restApiRootResourceId = resource.attrRootResourceId;
this.root = new RootResource(this, {}, this.restApiRootResourceId);

this._configureDeployment(props);
if (props.domainName) {
this.addDomainName('CustomDomain', props.domainName);
}

const cloudWatchRoleDefault = FeatureFlags.of(this).isEnabled(APIGATEWAY_DISABLE_CLOUDWATCH_ROLE) ? false : true;
const cloudWatchRole = props.cloudWatchRole ?? cloudWatchRoleDefault;
if (cloudWatchRole) {
this._configureCloudWatchRole(resource);
}

this._configureDeployment(props);
if (props.domainName) {
this.addDomainName('CustomDomain', props.domainName);
}
}
}

Expand Down
Expand Up @@ -80,7 +80,10 @@
"Ref": "myapiDeployment92F2CB49d7e5c9cfe50a1616e1cef4517d6b8f96"
},
"StageName": "prod"
}
},
"DependsOn": [
"myapiAccountEC421A0A"
]
},
"myapiCloudWatchRole095452E5": {
"Type": "AWS::IAM::Role",
Expand Down
Expand Up @@ -72,7 +72,10 @@
"Ref": "myapiDeployment92F2CB49a59bca458e4fac1fcd742212ded42a65"
},
"StageName": "prod"
}
},
"DependsOn": [
"myapiAccountEC421A0A"
]
},
"myapiCloudWatchRole095452E5": {
"Type": "AWS::IAM::Role",
Expand Down
Expand Up @@ -517,7 +517,10 @@
}
],
"StageName": "beta"
}
},
"DependsOn": [
"myapiAccountEC421A0A"
]
},
"myapiCloudWatchRole095452E5": {
"Type": "AWS::IAM::Role",
Expand Down
19 changes: 18 additions & 1 deletion packages/@aws-cdk/aws-apigateway/test/stage.test.ts
Expand Up @@ -70,7 +70,7 @@ describe('stage', () => {
});
});

test('stage depends on the CloudWatch role when it exists', () => {
test('RestApi - stage depends on the CloudWatch role when it exists', () => {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'test-api', { cloudWatchRole: true, deploy: false });
Expand All @@ -80,6 +80,23 @@ describe('stage', () => {
// WHEN
new apigateway.Stage(stack, 'my-stage', { deployment });

// THEN
Template.fromStack(stack).hasResource('AWS::ApiGateway::Stage', {
DependsOn: ['testapiAccount9B907665'],
});
});

test('SpecRestApi - stage depends on the CloudWatch role when it exists', () => {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.SpecRestApi(stack, 'test-api', { apiDefinition: apigateway.ApiDefinition.fromInline( { foo: 'bar' }) });
const deployment = new apigateway.Deployment(stack, 'my-deployment', { api });
api.root.addMethod('GET');

// WHEN
new apigateway.Stage(stack, 'my-stage', { deployment });

// THEN
Template.fromStack(stack).hasResource('AWS::ApiGateway::Stage', {
DependsOn: ['testapiAccount9B907665'],
});
Expand Down