A serverless solution to handle url redirects for static sites.
- ARN to a valid Amazon Certificate Mangager (ACM) certificate that covers your
FromDomain
name. HostedZoneId
of yourFromDomain
's Route53 record.
- If you previously used your
FromDomain
as 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
A
orAAAA
Route53 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/abc123
to redirectwww
to yourapex
domain (or visa versa).
- For example
- Be patient, deploying the
AWS::ApiGateway::DomainName
doesn't break any speed records! - Hit the
FromDomain
from your browser and you should be redirected to yourToDomain
, including any path.
Swap out
deploy
withupdate
to run again.delete
to tear it all down.
- When you enter
www.mcgilldevtech.com
in 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/about
goes tohttps://mcgilldevtech.com/about
,..dropping thewww
and enforcinghttps