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): support custom domain mappings #19368

Merged
merged 11 commits into from Mar 18, 2022

Conversation

moofish32
Copy link
Contributor

@moofish32 moofish32 commented Mar 12, 2022

fixes #18040

This adds support for custom domains with AppSync.

@gitpod-io
Copy link

gitpod-io bot commented Mar 12, 2022

@github-actions github-actions bot added the @aws-cdk/aws-appsync Related to AWS AppSync label Mar 12, 2022
* The hosted zone and CName must be configured in addition to this setting to
* enable custom domain URL
*
* @default - none a unique name is generated
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comma or parenthesis after "none" ?

This comment was marked as outdated.

```ts
import { Certificate } from '@aws-cdk/aws-certificatemanager';

declare const certificate: Certificate;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work? You're not initializing it to anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work? no. Can it compile this way? yes. This is something we are using in our examples for necessary properties that are not essential to the overall example. We don't want to clutter our examples with a new lambda.Function(this, 'myfn', {...}); each time we need one, so it is simpler to write declare const fn: lambda.Function and leave it to the user to provide the exact function they need if they want to use the example.

That being said, I feel like providing a real certificate is necessary to this example, since it is part of the domainName property we are demonstrating. So I do think in this situation we should provide a real certificate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I did not invent this pattern I modeled most of the work from the rest api pattern here

@kaizencc kaizencc assigned kaizencc and unassigned otaviomacedo Mar 15, 2022
@kaizencc kaizencc added p1 feature-request A feature should be added or improved. labels Mar 15, 2022
@kaizencc kaizencc changed the title feat(aws-appsync): enable support for custom domain mappings feat(appsync): support custom domain mappings Mar 15, 2022
@aws aws deleted a comment from msambol Mar 15, 2022
@aws aws deleted a comment from msambol Mar 15, 2022
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

Thanks @moofish32 for getting this started! Looks good, with a few minor comments.

packages/@aws-cdk/aws-appsync/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/README.md Show resolved Hide resolved
```ts
import { Certificate } from '@aws-cdk/aws-certificatemanager';

declare const certificate: Certificate;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work? no. Can it compile this way? yes. This is something we are using in our examples for necessary properties that are not essential to the overall example. We don't want to clutter our examples with a new lambda.Function(this, 'myfn', {...}); each time we need one, so it is simpler to write declare const fn: lambda.Function and leave it to the user to provide the exact function they need if they want to use the example.

That being said, I feel like providing a real certificate is necessary to this example, since it is part of the domainName property we are demonstrating. So I do think in this situation we should provide a real certificate.

packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts Outdated Show resolved Hide resolved
* The hosted zone and CName must be configured in addition to this setting to
* enable custom domain URL
*
* @default - none a unique name is generated

This comment was marked as outdated.

@@ -472,6 +495,18 @@ export class GraphqlApi extends GraphqlApiBase {
this.schema = props.schema ?? new Schema();
this.schemaResource = this.schema.bind(this);

if (props.domainName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In the docs for domainName you write that "The hosted zone and CName must be configured in addition to this setting to enable custom domain URL" but we do not check for that here.

Are we leaving that requirement as a deploy-time check right now? If so, we probably need to think about how we can make it a synth-time check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again based on how the rest api works today this is a separate action. I felt like we should tell the user to do this, but if we nested this all in this construct I think it would be doing too much. I assume the rest api developers felt the same way, but of course I do not know.

packages/@aws-cdk/aws-appsync/test/appsync.test.ts Outdated Show resolved Hide resolved
Co-authored-by: Kaizen Conroy <36202692+kaizen3031593@users.noreply.github.com>
@mergify mergify bot dismissed kaizencc’s stale review March 17, 2022 17:39

Pull request has been modified.

Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

Thanks @moofish32! Added in a few changes (mostly to the readme example, to get it to compile).

@mergify
Copy link
Contributor

mergify bot commented Mar 18, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 64c1dd7
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 8c7a4ac into aws:master Mar 18, 2022
@mergify
Copy link
Contributor

mergify bot commented Mar 18, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@sammy2077
Copy link

@moofish32
The code snippet in the README might not work when creating Route53 Record
image

If you define

const myDomainName = 'api.example.com';
new route53.CnameRecord(this, `CnameApiRecord`, {
  recordName: 'api',
  zone,
  domainName: myDomainName,
});

This is trying to create a DNS record (CNAME) for api.example.com to point to the same address
You need to target the CloudFront URL of the appsync domain.
Like this

new CnameRecord(this, `CnameApiRecord`, {
            recordName: 'api',
            zone,
            domainName: appsyncDomain.attrAppSyncDomainName
        });

See my working sample here #18040 (comment)

@sebastiansanio
Copy link

Is it possible to make this work with @aws-cdk/aws-appsync-alpha?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-appsync Related to AWS AppSync feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Appsync: Add support for custom domains
8 participants