Skip to content

Commit

Permalink
fix(apigateway): failing build on domain name with upercase
Browse files Browse the repository at this point in the history
Api Gateway doesn't accept domain name with upercase letters as per [its documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html#aws-resource-apigateway-domainname-properties).

This lead me to find out at CF deployment that my stack had an issue when this could have been discovered at build time.

fixes #8428
  • Loading branch information
matdumsa committed Jun 9, 2020
1 parent b8b084f commit 688e0a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-apigateway/lib/domain-name.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as acm from '@aws-cdk/aws-certificatemanager';
import { Construct, IResource, Resource } from '@aws-cdk/core';
import { Construct, IResource, Resource, Token } from '@aws-cdk/core';
import { CfnDomainName } from './apigateway.generated';
import { BasePathMapping, BasePathMappingOptions } from './base-path-mapping';
import { EndpointType, IRestApi } from './restapi';
Expand Down Expand Up @@ -102,6 +102,11 @@ export class DomainName extends Resource implements IDomainName {
const endpointType = props.endpointType || EndpointType.REGIONAL;
const edge = endpointType === EndpointType.EDGE;

if (!Token.isUnresolved(props.domainName) && /[A-Z]/.test(props.domainName)) {
throw new Error('domainName does not support uppercase letters. ' +
`got: '${props.domainName}'`);
}

const resource = new CfnDomainName(this, 'Resource', {
domainName: props.domainName,
certificateArn: edge ? props.certificate.certificateArn : undefined,
Expand Down
15 changes: 15 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/test.domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,21 @@ export = {
test.done();
},

'domain name cannot contain uppercase letters'(test: Test) {
// GIVEN
const stack = new Stack();
const certificate = new acm.Certificate(stack, 'cert', { domainName: 'someDomainWithUpercase.domain.com' });

// WHEN
test.throws(() => {
new apigw.DomainName(stack, 'someDomain', {domainName: 'someDomainWithUpercase.domain.com', certificate})
})

// THEN

test.done();
},

'multiple domain names can be added'(test: Test) {
// GIVEN
const domainName = 'my.domain.com';
Expand Down

0 comments on commit 688e0a0

Please sign in to comment.