A serverless solution to handle url redirects for static sites.
- ARN to a valid Amazon Certificate Mangager (ACM) certificate that covers your
FromDomainname. HostedZoneIdof yourFromDomain's Route53 record.
- If you previously used your
FromDomainas a CloudFront alias you must remove that before deploying this cloudformation. Domains can only be associated with 1 CloudFront distribution. - Ensure you don't have any existing
AorAAAARoute53 records for theFromDomain, these will be created for you. If you have prior records the deployment will fail.
- Run
bash run.sh deploy <FromDomain> <ToProtocol> <ToDomain> <HostedZoneId> <AcmArnForFromDomain>- For example
bash run.sh deploy www.mcgilldevtech.com https mcgilldevtech.com ABC123 arn:aws:acm:us-east-1:123456789012:certificate/abc123to redirectwwwto yourapexdomain (or visa versa).
- For example
- Be patient, deploying the
AWS::ApiGateway::DomainNamedoesn't break any speed records! - Hit the
FromDomainfrom your browser and you should be redirected to yourToDomain, including any path.
Swap out
deploywithupdateto run again.deleteto tear it all down.
- When you enter
www.mcgilldevtech.comin your browser Route53 directs you to API Gateway's CloudFront. - CloudFront
301's you tohttps://www.mcgilldevtech.com - That URL hits the lambda which pulls off the
FromDomain's path, if there is one, and reconstructs the url then301's clients to that URL. ie.www.mcgilldevtech.com/aboutgoes tohttps://mcgilldevtech.com/about,..dropping thewwwand enforcinghttps