enableAutoSubdomain does not seem to be working - Amplify CDK
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
- 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 subdomainsas 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 linedomain.mapSubDomain(main)) but i cant do this for other branches as i do not know the names ahead of time
Reproduction steps
- 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: ['*'],
});
- 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
Related - https://github.com/aws-amplify/amplify-hosting/issues/3072
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.
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.