Created
March 5, 2017 20:12
-
-
Save amosshapira/0e0eafe75832393351706a9d13bcec62 to your computer and use it in GitHub Desktop.
CloudFormation template to redirect "company.co.uk" to "company.com"
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", | |
"Description": "Redirect company.co.uk web site", | |
"Resources": { | |
"BucketCompanyCoUk": { | |
"Properties": { | |
"AccessControl": "PublicRead", | |
"BucketName": "company.co.uk", | |
"CorsConfiguration": { | |
"CorsRules": [ | |
{ | |
"AllowedHeaders": [ | |
"*" | |
], | |
"AllowedMethods": [ | |
"GET" | |
], | |
"AllowedOrigins": [ | |
"*" | |
], | |
"ExposedHeaders": [ | |
"Date" | |
], | |
"MaxAge": 3600 | |
} | |
] | |
}, | |
"WebsiteConfiguration": { | |
"RedirectAllRequestsTo": { | |
"HostName": "company.com", | |
"Protocol": "https" | |
} | |
} | |
}, | |
"Type": "AWS::S3::Bucket" | |
}, | |
"BucketPolicyCompanyCoUk": { | |
"DependsOn": "BucketCompanyCoUk", | |
"Properties": { | |
"Bucket": "company.co.uk", | |
"PolicyDocument": { | |
"Statement": [ | |
{ | |
"Action": [ | |
"s3:GetObject" | |
], | |
"Effect": "Allow", | |
"Principal": "*", | |
"Resource": "arn:aws:s3:::company.co.uk/*" | |
} | |
] | |
} | |
}, | |
"Type": "AWS::S3::BucketPolicy" | |
}, | |
"BucketPolicyWwwCompanyCoUk": { | |
"DependsOn": "BucketWwwCompanyCoUk", | |
"Properties": { | |
"Bucket": "www.company.co.uk", | |
"PolicyDocument": { | |
"Statement": [ | |
{ | |
"Action": [ | |
"s3:GetObject" | |
], | |
"Effect": "Allow", | |
"Principal": "*", | |
"Resource": "arn:aws:s3:::www.company.co.uk/*" | |
} | |
] | |
} | |
}, | |
"Type": "AWS::S3::BucketPolicy" | |
}, | |
"BucketWwwCompanyCoUk": { | |
"Properties": { | |
"AccessControl": "PublicRead", | |
"BucketName": "www.company.co.uk", | |
"CorsConfiguration": { | |
"CorsRules": [ | |
{ | |
"AllowedHeaders": [ | |
"*" | |
], | |
"AllowedMethods": [ | |
"GET" | |
], | |
"AllowedOrigins": [ | |
"*" | |
], | |
"ExposedHeaders": [ | |
"Date" | |
], | |
"MaxAge": 3600 | |
} | |
] | |
}, | |
"WebsiteConfiguration": { | |
"RedirectAllRequestsTo": { | |
"HostName": "company.com", | |
"Protocol": "https" | |
} | |
} | |
}, | |
"Type": "AWS::S3::Bucket" | |
}, | |
"DNSRecord": { | |
"Properties": { | |
"Comment": "Records for the root of company.co.uk", | |
"HostedZoneName": "company.co.uk.", | |
"RecordSets": [ | |
{ | |
"AliasTarget": { | |
"DNSName": { | |
"Fn::Join": [ | |
"", | |
[ | |
{ | |
"Fn::GetAtt": [ | |
"Distribution", | |
"DomainName" | |
] | |
}, | |
"." | |
] | |
] | |
}, | |
"HostedZoneId": "Z............2" | |
}, | |
"Name": "company.co.uk.", | |
"Type": "A" | |
}, | |
{ | |
"AliasTarget": { | |
"DNSName": { | |
"Fn::Join": [ | |
"", | |
[ | |
{ | |
"Fn::GetAtt": [ | |
"Distribution", | |
"DomainName" | |
] | |
}, | |
"." | |
] | |
] | |
}, | |
"HostedZoneId": "Z............2" | |
}, | |
"Name": "www.company.co.uk.", | |
"Type": "A" | |
} | |
] | |
}, | |
"Type": "AWS::Route53::RecordSetGroup" | |
}, | |
"Distribution": { | |
"DependsOn": [ | |
"BucketCompanyCoUk", | |
"BucketWwwCompanyCoUk" | |
], | |
"Properties": { | |
"DistributionConfig": { | |
"Aliases": [ | |
"company.co.uk", | |
"www.company.co.uk" | |
], | |
"DefaultCacheBehavior": { | |
"ForwardedValues": { | |
"QueryString": "false" | |
}, | |
"TargetOriginId": "bucketOriginCompanyCoUk", | |
"ViewerProtocolPolicy": "allow-all" | |
}, | |
"Enabled": "true", | |
"Origins": [ | |
{ | |
"CustomOriginConfig": { | |
"OriginProtocolPolicy": "http-only" | |
}, | |
"DomainName": "company.co.uk.s3-website-us-east-1.amazonaws.com", | |
"Id": "bucketOriginCompanyCoUk" | |
}, | |
{ | |
"CustomOriginConfig": { | |
"OriginProtocolPolicy": "http-only" | |
}, | |
"DomainName": "www.company.co.uk.s3-website-us-east-1.amazonaws.com", | |
"Id": "bucketOriginWwwCompanyCoUk" | |
} | |
], | |
"PriceClass": "PriceClass_All", | |
"ViewerCertificate": { | |
"AcmCertificateArn": "arn:aws:acm:us-east-1:aws-account:certificate/ACM-issued-ssl-certificate-id", | |
"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