A few weeks ago, I updated my CDK stack to access Cognito via a custom URL (details in https://repost.aws/questions/QUe6Vdvu1HRtWhPgGwOx69SQ).
Last week, after a deployment, the alias https://auth.develop.mogaland.io
stopped responding and it's only after a visit to the AWS console that I noticed the AWS-managed CloudFront distribution changed! I manually updated the Route53 record for the alias to point to the new distribution.
Once the domain is added, I can only get the cloudFrontDomainName
from the result of the user.PooladdDomain()
function. The cloudFrontDistributionId
is not available... And w/o that distribution identifier, I can't expect to create A and AAAA alias later records to adjust the custom domain with the updated distribution...
// Add the custom domain to the user pool
const certificate = Certificate.fromCertificateArn(this, 'domainCert', props.acmCertificateARN);
const userPoolDomain = this.userPool.addDomain('Custom Domain', {
customDomain: {
domainName: `auth.${props.stageName}.mogaland.io`,
certificate,
},
});
// Get the reference of AWS-managed CloudFront distribution
const awsManagedDistribution = Distribution.fromDistributionAttributes(this, 'AWS Managed Distribution', {
domainName: userPoolDomain.cloudFrontDomainName,
// distributionId: ???, // <= w/o the distributionId, I can't later update the alias records
});
// Get the Route53 hosted zone
const hostedZone = HostedZone.fromHostedZoneAttributes(this, 'Hosted Zone', {
hostedZoneId: props.hostedZoneId, // some value like 'Z' plus 20 characters
zoneName: `${props.stageName}.mogaland.io`,
});
// Update the A and AAAA records (update b/c of deletion before creation)
new ARecord(this, 'aliasRecord', {
zone: hostedZone,
recordName: 'auth',
deleteExisting: true,
target: RecordTarget.fromAlias(new CloudFrontTarget(awsManagedDistribution)),
});
new AaaaRecord(this, 'aaaAliasRecord', {
zone: hostedZone,
recordName: 'auth',
deleteExisting: true,
target: RecordTarget.fromAlias(new CloudFrontTarget(awsManagedDistribution)),
});
Maybe there's another way to get the reference of the AWS-managed CloudFront distribution?