Skip to content

Commit

Permalink
fix(appsync): domain name api association fails when domain name crea…
Browse files Browse the repository at this point in the history
…tion is in the same stack (#20173)

Fixes #18395 and other issues where defining domain name in `aws-appsync-alpha` will fail because domain name is not created before the domain name association.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kochie authored Jul 14, 2022
1 parent 9c0ccca commit c1495f0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,18 @@ export class GraphqlApi extends GraphqlApiBase {
this.schemaResource = this.schema.bind(this);

if (props.domainName) {
new CfnDomainName(this, 'DomainName', {
const domainName = new CfnDomainName(this, 'DomainName', {
domainName: props.domainName.domainName,
certificateArn: props.domainName.certificate.certificateArn,
description: `domain for ${this.name} at ${this.graphqlUrl}`,
});

new CfnDomainNameApiAssociation(this, 'DomainAssociation', {
const domainNameAssociation = new CfnDomainNameApiAssociation(this, 'DomainAssociation', {
domainName: props.domainName.domainName,
apiId: this.apiId,
});

domainNameAssociation.addDependsOn(domainName);
}

if (modes.some((mode) => mode.authorizationType === AuthorizationType.API_KEY)) {
Expand Down
43 changes: 43 additions & 0 deletions packages/@aws-cdk/aws-appsync/test/appsync-domain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as path from 'path';
import { Template } from '@aws-cdk/assertions';
import * as acm from '@aws-cdk/aws-certificatemanager';
import { Certificate } from '@aws-cdk/aws-certificatemanager';
import * as cdk from '@aws-cdk/core';
import * as appsync from '../lib';

// GLOBAL GIVEN
let stack: cdk.Stack;
let certificate: acm.Certificate;

beforeEach(() => {
stack = new cdk.Stack();
certificate = new Certificate(stack, 'certificate', {
domainName: 'aws.amazon.com',
});
});

describe('Tests of AppSync Domain Name', () => {
test('DomainNameAssociation depends on DomainName construct', () => {
new appsync.GraphqlApi(stack, 'baseApi', {
name: 'api',
schema: appsync.Schema.fromAsset(
path.join(__dirname, 'appsync.test.graphql'),
),
domainName: {
certificate,
domainName: 'aws.amazon.com',
},
});

const domainName = Template.fromStack(stack).findResources(
'AWS::AppSync::DomainName',
);

Template.fromStack(stack).hasResource(
'AWS::AppSync::DomainNameApiAssociation',
{
DependsOn: [Object.keys(domainName)[0]],
},
);
});
});

0 comments on commit c1495f0

Please sign in to comment.