amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

enableAutoSubdomain does not seem to be working - Amplify CDK

Open Titi-layo opened this issue 3 years ago • 2 comments

Before opening, please confirm:

  • [X] I have checked to see if my question is addressed in the FAQ.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

App Id

NEW_APP

AWS Region

us-east-1

Amplify Hosting feature

Not Applicable

Describe the bug

I am using CDK and following the docs https://constructs.dev/packages/@aws-cdk/aws-amplify-alpha/v/2.50.0-alpha.0/api/Domain?lang=typescript


const domain = amplifyApp.addDomain(`xxxxx.com`, {
      enableAutoSubdomain: true,
      autoSubdomainCreationPatterns: ['*'],
    });

As mentioned in the docs, I have used the code above to enable enableAutoSubdomain and when i try to deploy it to CDK, i get an error saying :

The domain doesn't contain any subdomains

  1. When I then add this to the code mentioned above -> const main = amplifyApp.addBranch('main') domain.mapSubDomain(main);

I stop getting the error and the app deploys successfully. However in the amplify console i then only see my main branch have a subdomain i.e. main.xxxxx.com but when i add new branches to the connected github repo and check the amplify console, these branches do not have a sub-domain automatically created

Expected behavior

  • When enableAutoSubdomain is set to true in amplify CDK, all branches connected to the amplify app should automatically have a subdomain in the format - branch_name.domainName.com
  • I should not have to explicitly map a branch to a subdomain (i.e. domain.mapSubDomain(main)) to be able to successfully deploy to cdk
  • I should not be getting the error The domain doesn't contain any subdomains as i imagine the point of enableAutoSubdomain is that the subdomain depends on the branch name and usually, branches would be created in future (I managed to tackle this only because usually a repository will have a main branch and so i was able to add the line domain.mapSubDomain(main)) but i cant do this for other branches as i do not know the names ahead of time

Reproduction steps

  1. In Amplify CDK use the code below and try to deploy
const amplifyApp = new amplify.App(this, 'xxxxx, {
     sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
       owner: 'xxxxxxx',
       repository: 'xxxxxxxi',
       oauthToken: cdk.SecretValue.secretsManager('xxxxxx', {
         jsonField: 'xxxxxx',
       }),
     }),
     role: role,
     autoBranchCreation: {
       patterns: ['*'],
     },
     autoBranchDeletion: true,
   });

const domain = amplifyApp.addDomain(`xxxxx.com`, {
      enableAutoSubdomain: true,
      autoSubdomainCreationPatterns: ['*'],
    });
  1. Add the lines of code below :

const main = amplifyApp.addBranch('main') domain.mapSubDomain(main);

Build Settings

No response

Log output

# Put your logs below this line


Additional information

No response

Titi-layo avatar Nov 09 '22 23:11 Titi-layo

Related - https://github.com/aws-amplify/amplify-hosting/issues/3072

nadetastic avatar Jun 09 '23 01:06 nadetastic

I have noticed the same issue, it seems to work fine when I set this up via the Amplify console, so I know I have the hosted zone set up correctly.

It is as if this configuration is ignored or defaults to off.

I noticed that when I make changes to the domain options and then run CDK deploy, CDK thinks there are not changes to the infra including the amplify app so nothing happens.

We recently got loads of new Amplify CDK constructs for Amplify backend connections but the main Amplify app construct needs some love.

Develliot avatar May 23 '24 12:05 Develliot

Any update on this?

I'm having what I believe to be the same issue, using aws-cdk-lib 2.172.0 (build 0f666c5) and @aws-sdk/[email protected].

I create an Amplify app and then attach a custom domain with auto subdomaining enabled via:

        declare const amplifyApp: amplify.App

        const mainBranch = amplifyApp.addBranch("MainBranch", {
            autoBuild: false,
            branchName: "main",
            pullRequestPreview: true,
        });

        const domain = amplifyApp.addDomain(
            `${this.mainStackName}-AmplifyDomain`,
            {
                autoSubdomainCreationPatterns: ["*"],
                domainName: hostedZone.zoneName,
                enableAutoSubdomain: true,
            }
        );
        domain.mapRoot(mainBranch);
        domain.mapSubDomain(mainBranch, "www");

However, when I later create a new branch on the app via the AWS SDK (specifically, @aws-sdk/[email protected]), the created app uses the default xxx.amplifyapp.com domain rather than my custom domain.

ETA: The custom domain works fine for the main branch, as does its www subdomain.

ScottRobinson03 avatar Jan 16 '25 09:01 ScottRobinson03