-
Notifications
You must be signed in to change notification settings - Fork 9
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:
- This sample generates a non-reproducible random domain name at synthesis time via
Math.random- so every re-synthesis will change the target domain name, and - CloudFormation does not seem to support 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 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