Last active
February 17, 2017 15:45
-
-
Save cagataygurturk/18ea92619037bd59b84e57f295c9fd30 to your computer and use it in GitHub Desktop.
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", | |
"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