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

(AWS.AppSync): Creation of CfnDomainNameApiAssociation fails when CfnDomainName object that association applies to is created under the same stack #18395

Closed
TomaszCypser opened this issue Jan 13, 2022 · 2 comments · Fixed by #20173
Labels
@aws-cdk/aws-appsync Related to AWS AppSync bug This issue is a bug. p2

Comments

@TomaszCypser
Copy link

TomaszCypser commented Jan 13, 2022

What is the problem?

Creation of CfnDomainNameApiAssociation and CfnDomainName that the previously mentioned object applies to fails, if is being done under the same stack. If I were to separate them into two different stacks, the error would not occur.

Reproduction Steps

  1. Create GraphqlApi instance.
  2. Setup domain name using this code snippet:
        [..]
            var certificate = new DnsValidatedCertificate(this, $"XXX-Api-Certificate",
                new DnsValidatedCertificateProps
                {
                    DomainName = props.DnsName,
                    Region = "us-east-1",
                    HostedZone = props.HostedZone
                });

            var cfnDomainName = new CfnDomainName(this, "XXX-Domain-Name",
                new CfnDomainNameProps
                {
                    CertificateArn = certificate.CertificateArn,
                    Description = "XXX domain name",
                    DomainName = props.DnsName,
                });

            new CfnDomainNameApiAssociation(this, "XXX-Domain-Name-Api-Association",
                new CfnDomainNameApiAssociationProps
                {
                    ApiId = graphqlApi.ApiId,
                    DomainName = props.DnsName
                });

            new CnameRecord(this, $"XXX-Domain-Name-CNameRecord", new CnameRecordProps
            {
                RecordName = props.DnsName,
                DomainName = cfnDomainName.AttrAppSyncDomainName,
                Zone = props.HostedZone
            });
        [..]

What did you expect to happen?

AppSync API with a custom domain name and API association would be created.

What actually happened?

XXX |  5/58 | 6:47:13 AM | CREATE_FAILED        | AWS::AppSync::DomainNameApiAssociation | XXX (XXX) Resource handler returned message: "Resource of type 'AWS::AppSync::DomainNameApiAssociation' with identifier 'null' was not found." (RequestToken: 7349ad3a-7dda-4af5-90d9-732ecebe1fbf, HandlerErrorCode: NotFound)

CDK CLI Version

2.7.0

Framework Version

2.7.0

Node.js Version

14.18.3

OS

Debian 10

Language

.NET

Language Version

.net core 3.1

Other information

Observed the same behavior as well with CDK version 1.138.2. Following separation would not show the above error.

    // First stack
        [..]
            var certificate = new DnsValidatedCertificate(this, $"XXX-Api-Certificate",
                new DnsValidatedCertificateProps
                {
                    DomainName = props.DnsName,
                    Region = "us-east-1",
                    HostedZone = props.HostedZone
                });

            var cfnDomainName = new CfnDomainName(this, "XXX-Domain-Name",
                new CfnDomainNameProps
                {
                    CertificateArn = certificate.CertificateArn,
                    Description = "XXX domain name",
                    DomainName = props.DnsName,
                });
        [..]
        
    // Second stack
        [..]
            new CfnDomainNameApiAssociation(this, "XXX-Domain-Name-Api-Association",
                new CfnDomainNameApiAssociationProps
                {
                    ApiId = graphqlApi.ApiId,
                    DomainName = props.DnsName
                });

            new CnameRecord(this, $"XXX-Domain-Name-CNameRecord", new CnameRecordProps
            {
                RecordName = props.DnsName,
                DomainName = cfnDomainName.AttrAppSyncDomainName,
                Zone = props.HostedZone
            });
        [..]
@TomaszCypser TomaszCypser added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 13, 2022
@github-actions github-actions bot added the @aws-cdk/aws-appsync Related to AWS AppSync label Jan 13, 2022
@TomaszCypser TomaszCypser changed the title (AWS.AppSync): Creating CfnDomainNameApiAssociation fails when refering to GraphqlApi's object ApiId property (AWS.AppSync): Creating CfnDomainNameApiAssociation fails when CfnDomainName object is created under the same stack Jan 13, 2022
@TomaszCypser TomaszCypser changed the title (AWS.AppSync): Creating CfnDomainNameApiAssociation fails when CfnDomainName object is created under the same stack (AWS.AppSync): Creation CfnDomainNameApiAssociation fails when CfnDomainName object that association applies to is created under the same stack Jan 13, 2022
@TomaszCypser TomaszCypser changed the title (AWS.AppSync): Creation CfnDomainNameApiAssociation fails when CfnDomainName object that association applies to is created under the same stack (AWS.AppSync): Creation of CfnDomainNameApiAssociation fails when CfnDomainName object that association applies to is created under the same stack Jan 13, 2022
@ryparker ryparker added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jan 13, 2022
@otaviomacedo otaviomacedo removed their assignment Jan 25, 2022
@fwang
Copy link

fwang commented Apr 14, 2022

Ran into the same issue. In CloudTrail, the associate API made by CFN failed with the error:

{
   ...
   "errorCode": "NotFoundException",
    "responseElements": {
        "message": "Domain name not found."
    },
   ...
}

It seems we need to add a dependency for AWS::AppSync::DomainNameApiAssociation to depend on AWS::AppSync::DomainName. Currently, DomainNameApiAssociation might be created before DomainName is created, hence the above error.

We manually added the dependency as a workaround.
https://github.com/serverless-stack/serverless-stack/blob/master/packages/resources/src/AppSyncApi.ts#L689-L711

@mergify mergify bot closed this as completed in #20173 Jul 14, 2022
mergify bot pushed a commit that referenced this issue Jul 14, 2022
…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*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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 bug This issue is a bug. p2
Projects
None yet
4 participants