forked from AHinMaine/AWSCloudFormation-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
S3_With_CloudFront_Distribution.template
74 lines (67 loc) · 3.16 KB
/
S3_With_CloudFront_Distribution.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Sample Template S3_With_CloudFront_Distribution: Sample template showing how to create a website with a custom DNS name, hosted on Amazon S3 and served via Amazone CloudFront. It assumes you already have a Hosted Zone registered with Amazon Route 53. **WARNING** This template creates an Amazon Route 53 DNS record, an S3 bucket and a CloudFront distribution. You will be billed for the AWS resources used if you create a stack from this template.",
"Parameters" : {
"HostedZone" : {
"Type" : "String",
"Description" : "The DNS name of an existing Amazon Route 53 hosted zone"
}
},
"Mappings" : {
"RegionMap" : {
"us-east-1" : { "s3BucketDomain" : ".s3.amazonaws.com" },
"us-west-1" : { "s3BucketDomain" : ".s3-us-west-1.amazonaws.com" },
"us-west-2" : { "s3BucketDomain" : ".s3-us-west-2.amazonaws.com" },
"eu-west-1" : { "s3BucketDomain" : ".s3-eu-west-1.amazonaws.com" },
"sa-east-1" : { "s3BucketDomain" : ".s3-sa-east-1.amazonaws.com" },
"ap-northeast-1" : { "s3BucketDomain" : ".s3-ap-northeast-1.amazonaws.com" },
"ap-southeast-1" : { "s3BucketDomain" : ".s3-ap-southeast-1.amazonaws.com" },
"ap-southeast-2" : { "s3BucketDomain" : ".s3-ap-southeast-2.amazonaws.com" }
}
},
"Resources" : {
"S3BucketForWebsiteContent" : {
"Type" : "AWS::S3::Bucket",
"Properties" : {
}
},
"WebsiteCDN" : {
"Type" : "AWS::CloudFront::Distribution",
"Properties" : {
"DistributionConfig" : {
"Comment" : "CDN for S3-backed website",
"CustomOrigin" : {
"DNSName": { "Fn::Join" : ["", [{"Ref" : "S3BucketForWebsiteContent"}, { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "s3BucketDomain" ]} ]]},
"HTTPPort" : "80",
"HTTPSPort" : "443",
"OriginProtocolPolicy" : "http-only"
},
"Enabled" : "true",
"DefaultRootObject" : "index.html",
"CNAMEs" : [{ "Fn::Join" : [ "", [{"Ref" : "AWS::StackId"}, ".", {"Ref" : "AWS::Region"}, ".", { "Ref" : "HostedZone" }]]}]
}
}
},
"WebsiteDNSName" : {
"Type" : "AWS::Route53::RecordSet",
"Properties" : {
"HostedZoneName" : { "Fn::Join" : [ "", [{ "Ref" : "HostedZone" }, "."]]},
"Comment" : "CNAME redirect custom name to CloudFront distribution",
"Name" : { "Fn::Join" : [ "", [{"Ref" : "AWS::StackId"}, ".", {"Ref" : "AWS::Region"}, ".", { "Ref" : "HostedZone" }]]},
"Type" : "CNAME",
"TTL" : "900",
"ResourceRecords" : [{ "Fn::Join" : [ "", ["http://", {"Fn::GetAtt" : ["WebsiteCDN", "DomainName"]} ]]}]
}
}
},
"Outputs" : {
"WebsiteURL" : {
"Value" : {"Fn::Join" : [ "", ["http://", {"Ref" : "WebsiteDNSName"} ]] },
"Description" : "The URL of the newly created website"
},
"BucketName" : {
"Value" : { "Ref" : "S3BucketForWebsiteContent" },
"Description" : "Name of S3 bucket to hold website content"
}
}
}