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

feat(appsync): expose the AppSyncDomain of the custom domain of an AppSync api #21554

Merged
merged 4 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-appsync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ const zone = route53.HostedZone.fromHostedZoneAttributes(this, `HostedZone`, {
new route53.CnameRecord(this, `CnameApiRecord`, {
recordName: 'api',
zone,
domainName: myDomainName,
domainName: api.appSyncDomainName!,
});
```

Expand Down
9 changes: 8 additions & 1 deletion packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,13 @@ export class GraphqlApi extends GraphqlApiBase {
*/
public readonly apiKey?: string;

/**
* the associated custom AppSync domain, if present
*
* @default - no custom associated domain
*/
public readonly appSyncDomainName?: string;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* the associated custom AppSync domain, if present
*
* @default - no custom associated domain
*/
public readonly appSyncDomainName?: string;
/**
* The associated domain name provided by AppSync
*/
public readonly appSyncDomainName: string;

domainName.attrAppSyncDomainName seems to be always available. Is there a reason why you made this optional at first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The domainName resource is only created when you pass the domainName properties in the api. So when creating a minimal api it will not create an AWS::AppSync::DomainName or an AWS::AppSync::DomainNameApiAssociation and therefore you don't have the appSyncDomainName.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay that makes sense. let's update the comment then to make this clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I only just saw this comment appear. I have changed it a bit to be even more clear when you are requesting the appSyncDomainName without a domainName configuration.

/**
* the CloudWatch Log Group for this API
*/
Expand Down Expand Up @@ -515,7 +522,7 @@ export class GraphqlApi extends GraphqlApiBase {
certificateArn: props.domainName.certificate.certificateArn,
description: `domain for ${this.name} at ${this.graphqlUrl}`,
});

this.appSyncDomainName = domainName.attrAppSyncDomainName;
const domainNameAssociation = new CfnDomainNameApiAssociation(this, 'DomainAssociation', {
domainName: props.domainName.domainName,
apiId: this.apiId,
Expand Down
15 changes: 15 additions & 0 deletions packages/@aws-cdk/aws-appsync/test/appsync-domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,19 @@ describe('Tests of AppSync Domain Name', () => {
},
);
});

test('domainNameAppSyncDomainName exposes the domain of the associated AWS::AppSync::DomainName', () => {
const api = new appsync.GraphqlApi(stack, 'baseApi', {
name: 'api',
schema: appsync.Schema.fromAsset(
path.join(__dirname, 'appsync.test.graphql'),
),
domainName: {
certificate,
domainName: 'aws.amazon.com',
},
});

expect(stack.resolve(api.appSyncDomainName)).toEqual({ 'Fn::GetAtt': ['baseApiDomainName52E3D63D', 'AppSyncDomainName'] });
});
});