Skip to content

Instantly share code, notes, and snippets.

@cagataygurturk
Last active February 17, 2017 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cagataygurturk/18ea92619037bd59b84e57f295c9fd30 to your computer and use it in GitHub Desktop.
Save cagataygurturk/18ea92619037bd59b84e57f295c9fd30 to your computer and use it in GitHub Desktop.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"DomainName": {
"Description": "Domain name you want to redirect (without www)",
"Type": "String"
},
"HostedZoneId": {
"Type": "AWS::Route53::HostedZone::Id",
"Description": "Route53 Hosted Zone Id that your domain is served in"
}
},
"Conditions": {
"CreateResources": {
"Fn::Equals": [
{
"Ref": "AWS::Region"
},
"us-east-1"
]
}
},
"Resources": {
"SSLCertificate": {
"Type": "AWS::CertificateManager::Certificate",
"Properties": {
"DomainName": {
"Fn::Join": [
".",
[
"www",
{
"Ref": "DomainName"
}
]
]
}
}
},
"S3Bucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": {
"Fn::Join": [
".",
[
"www",
{
"Ref": "DomainName"
}
]
]
},
"WebsiteConfiguration": {
"RedirectAllRequestsTo": {
"HostName": {
"Ref": "DomainName"
}
}
}
}
},
"CDNDistribution": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"Enabled": "true",
"Comment": {
"Fn::Join": [
" ",
[
"Redirection for",
{
"Ref": "DomainName"
}
]
]
},
"Aliases": [
{
"Fn::Join": [
".",
[
"www",
{
"Ref": "DomainName"
}
]
]
}
],
"Origins": [
{
"Id": "s3Origin",
"DomainName": {
"Fn::Join": [
"",
[
"www.",
{
"Ref": "DomainName"
},
".s3-website-",
{
"Ref": "AWS::Region"
},
".amazonaws.com"
]
]
},
"CustomOriginConfig": {
"OriginProtocolPolicy": "http-only"
}
}
],
"DefaultCacheBehavior": {
"AllowedMethods": [
"DELETE",
"GET",
"HEAD",
"OPTIONS",
"PATCH",
"POST",
"PUT"
],
"TargetOriginId": "s3Origin",
"ForwardedValues": {
"QueryString": "false",
"Cookies": {
"Forward": "none"
}
},
"ViewerProtocolPolicy": "allow-all"
},
"ViewerCertificate": {
"SslSupportMethod": "sni-only",
"AcmCertificateArn": {
"Ref": "SSLCertificate"
}
}
}
}
},
"DNSRecord": {
"Type": "AWS::Route53::RecordSetGroup",
"Properties": {
"HostedZoneId": {
"Ref": "HostedZoneId"
},
"RecordSets": [
{
"Name": {
"Fn::Join": [
".",
[
"www",
{
"Ref": "DomainName"
}
]
]
},
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"DNSName": {
"Fn::GetAtt": [
"CDNDistribution",
"DomainName"
]
}
}
}
]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment