Skip to content

Commit

Permalink
fix(apigateway): deployment fails when domain name has uppercase lett…
Browse files Browse the repository at this point in the history
…ers (#8456)

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



----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
matdumsa committed Jun 16, 2020
1 parent bd1c7fe commit 1e6a8e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-apigateway/lib/domain-name.ts
@@ -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
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/test.domains.ts
Expand Up @@ -267,6 +267,20 @@ 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});
}, /uppercase/);

// THEN
test.done();
},

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

0 comments on commit 1e6a8e9

Please sign in to comment.