aws-amplify / aws-amplify/amplify-hosting

enableAutoSubdomain does not seem to be working - Amplify CDK

Open
#3,102 5 comments 3 reactions 0 assignees View on GitHub
investigating question
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [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](https://constructs.dev/packages/@aws-cdk/aws-amplify-alpha/v/2.50.0-alpha.0/api/Domain?lang=typescript)

1.
```

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`

2. 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: ['*'],
});
```

2. 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_

Contributor guide

Open the contributing guide

Research direction

Start with the Amplify CDK Domain API documentation linked in the report and the addDomain, enableAutoSubdomain, autoSubdomainCreationPatterns, addBranch, and mapSubDomain entry points. Reproduce the deployment with the supplied TypeScript configuration, then verify whether future auto-created branches receive subdomains and whether deployment succeeds without an explicit mapping.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, github, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.