Last active
August 5, 2023 12:12
-
-
Save fancyremarker/5752f108a3506c7e6c189f6c9a11f809 to your computer and use it in GitHub Desktop.
Redirect all requests to a different static URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Outputs": { | |
"DistributionHostname": { | |
"Description": "Use this domain name in your DNS provider.", | |
"Value": { | |
"Fn::GetAtt": [ | |
"RootDistribution", | |
"DomainName" | |
] | |
} | |
} | |
}, | |
"Parameters": { | |
"Domain": { | |
"Description": "Root domain for your website, which you want to redirect from (e.g.: example.com)", | |
"Type": "String" | |
}, | |
"RootBucket": { | |
"Description": "Name of the S3 bucket that hosts your static redirect", | |
"Type": "String" | |
} | |
}, | |
"Resources": { | |
"RootCertificate": { | |
"Properties": { | |
"DomainName": { | |
"Ref": "Domain" | |
} | |
}, | |
"Type": "AWS::CertificateManager::Certificate" | |
}, | |
"RootDistribution": { | |
"Properties": { | |
"DistributionConfig": { | |
"Aliases": [ | |
{ | |
"Ref": "Domain" | |
} | |
], | |
"DefaultCacheBehavior": { | |
"ForwardedValues": { | |
"QueryString": true | |
}, | |
"MinTTL": "0", | |
"MaxTTL": "3600", | |
"DefaultTTL": "3600", | |
"SmoothStreaming": false, | |
"TargetOriginId": { | |
"Ref": "RootBucket" | |
}, | |
"ViewerProtocolPolicy": "allow-all" | |
}, | |
"Enabled": true, | |
"Origins": [ | |
{ | |
"CustomOriginConfig": { | |
"OriginProtocolPolicy": "http-only" | |
}, | |
"DomainName": { | |
"Fn::Join": [ | |
"", | |
[ | |
{ "Ref": "RootBucket" }, | |
".s3-website-", | |
{ "Ref" : "AWS::Region" }, | |
".amazonaws.com" | |
] | |
] | |
}, | |
"Id": { | |
"Ref": "RootBucket" | |
} | |
} | |
], | |
"PriceClass": "PriceClass_100", | |
"ViewerCertificate": { | |
"AcmCertificateArn": { | |
"Ref": "RootCertificate" | |
}, | |
"SslSupportMethod": "sni-only" | |
} | |
} | |
}, | |
"Type": "AWS::CloudFront::Distribution" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment