From 6e3448a7f39fab54d6c1e72cc1983e5b27926eea Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Tue, 24 Aug 2021 13:25:25 +0100 Subject: [PATCH] fix(apigatewayv2): ApiMapping does not depend on DomainName When an ApiMapping resource is deployed using the Domain defined in the DomainName resource, the DomainName resource must be deployed before the ApiMapping resource. Since the current logic uses the CloudFormation Output of DomainName as a fall back, preferring the user provided string first, this dependency is not expressed in the resulting template. Remove the preference for the user provided string, will inform synthesis that the dependency must be declared. fixes #15464 --- .../@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts | 2 +- .../aws-apigatewayv2/test/http/domain-name.test.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts b/packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts index dca1a60bd4548..6b1123512c678 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts +++ b/packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts @@ -98,7 +98,7 @@ export class DomainName extends Resource implements IDomainName { ], }; const resource = new CfnDomainName(this, 'Resource', domainNameProps); - this.name = props.domainName ?? resource.ref; + this.name = resource.ref; this.regionalDomainName = Token.asString(resource.getAtt('RegionalDomainName')); this.regionalHostedZoneId = Token.asString(resource.getAtt('RegionalHostedZoneId')); } diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/domain-name.test.ts b/packages/@aws-cdk/aws-apigatewayv2/test/http/domain-name.test.ts index 30c981a1da1d5..2d0d856c7ae15 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/domain-name.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2/test/http/domain-name.test.ts @@ -102,7 +102,9 @@ describe('DomainName', () => { ApiId: { Ref: 'ApiF70053CD', }, - DomainName: 'example.com', + DomainName: { + Ref: 'DNFDC76583', + }, Stage: 'beta', ApiMappingKey: 'beta', }); @@ -139,7 +141,9 @@ describe('DomainName', () => { ApiId: { Ref: 'ApiF70053CD', }, - DomainName: 'example.com', + DomainName: { + Ref: 'DNFDC76583', + }, Stage: '$default', }); });