aws-samples / aws-samples/foundational-llm-chat
Alternative solution for Cognito domain name issues
- Dominant language
- Python
- Stars
- 36
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
As noted in the README, this sample currently needs a `cognito_domain` configuration set for any subsequent re-deployments after the initial - the reasons being:
1. This sample [generates](https://github.com/aws-samples/foundational-llm-chat/blob/c502b461360833fa2d03f873b3a3680c4abd318d/lib/authentication/index.ts#L81) a non-reproducible random domain name at synthesis time via `Math.random` - so every re-synthesis will change the target domain name, and
2. CloudFormation [does not seem to support](https://github.com/aws/aws-cdk/issues/10062) updating the name of a previously-deployed domain.
There's not much we can do about (2), but I think (1) could actually be fixable.
Instead of Math.random, we could use logic similar to CDK's internal [generatePhysicalName utility](https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/core/lib/private/physical-name-generator.ts) to create a name which is deterministically repeatable *but* still conditional on the target [account ID, region, stack name, and fully-qualified construct node path] for the deployment.
With this solution (assuming we need to keep the `prefix` as part of the generated domain name), users would only potentially run in to trouble if they modified the prefix after first deployment. If having the prefix on the URL isn't necessary then even that constraint could be dropped I think: Changing any of the other things (stack name, node path, etc) should normally result in destroying & re-creating the Cognito pool anyway.
The main trade-off would be that users would see an error if they try to synthesize a region- or account-agnostic CloudFormation template from the app - but I'm not actually sure if that's possible today either? Certainly seems a much less common use-case than just deploying the CDK to a target environment.
---
I'm currently testing a tentative solution - happy to raise in PR if it'd be of interest & seems to work
Contributor guide
Research direction
Start with the README and lib/authentication/index.ts around line 81, then compare the current Math.random approach with CDK's physical-name-generator utility. Verify whether the generated Cognito domain can be repeatable for the account, region, stack name, and construct path, while considering the behavior of region- or account-agnostic synthesis. Done means subsequent re-synthesis no longer requires manually setting cognito_domain.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- authentication, cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100