-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudformation.yaml
More file actions
executable file
·121 lines (107 loc) · 3.29 KB
/
Copy pathcloudformation.yaml
File metadata and controls
executable file
·121 lines (107 loc) · 3.29 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
AWSTemplateFormatVersion: "2010-09-09"
Description: "Infrastructure for avautismcenter.com and antelopevalleyautismcenter.com"
Parameters:
PrimaryDomain:
Type: String
Default: "avautismcenter.com"
Description: "Primary domain for the website"
RedirectDomain:
Type: String
Default: "antelopevalleyautismcenter.com"
Description: "Redirect domain to the primary domain"
BucketName:
Type: String
Default: "www.avautismcenter.com"
Description: "Bucket name for the primary website"
Resources:
PrimaryBucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: !Ref BucketName
WebsiteConfiguration:
IndexDocument: "index.html"
RedirectBucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: !Ref RedirectDomain
WebsiteConfiguration:
RedirectAllRequestsTo:
HostName: !Ref PrimaryDomain
Protocol: "https"
PrimaryBucketPolicy:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref PrimaryBucket
PolicyDocument:
Statement:
- Effect: "Allow"
Principal: "*"
Action: "s3:GetObject"
Resource: !Sub "arn:aws:s3:::${BucketName}/*"
ACMCertificate:
Type: "AWS::CertificateManager::Certificate"
Properties:
DomainName: !Ref PrimaryDomain
SubjectAlternativeNames:
- !Sub "www.${PrimaryDomain}"
- !Ref RedirectDomain
ValidationMethod: "DNS"
CloudFrontDistribution:
Type: "AWS::CloudFront::Distribution"
Properties:
DistributionConfig:
Enabled: true
Origins:
- Id: "S3Origin"
DomainName: !GetAtt PrimaryBucket.RegionalDomainName
S3OriginConfig: {}
DefaultCacheBehavior:
TargetOriginId: "S3Origin"
ViewerProtocolPolicy: "redirect-to-https"
AllowedMethods:
- "GET"
- "HEAD"
CachedMethods:
- "GET"
- "HEAD"
ForwardedValues:
QueryString: false
Cookies:
Forward: "none"
ViewerCertificate:
AcmCertificateArn: !Ref ACMCertificate
SslSupportMethod: "sni-only"
DefaultRootObject: "index.html"
Aliases:
- !Ref PrimaryDomain
- !Sub "www.${PrimaryDomain}"
Route53HostedZonePrimary:
Type: "AWS::Route53::HostedZone"
Properties:
Name: !Ref PrimaryDomain
Route53HostedZoneRedirect:
Type: "AWS::Route53::HostedZone"
Properties:
Name: !Ref RedirectDomain
Route53RecordSetPrimary:
Type: "AWS::Route53::RecordSet"
Properties:
HostedZoneId: !Ref Route53HostedZonePrimary
Name: !Sub "www.${PrimaryDomain}"
Type: "A"
AliasTarget:
HostedZoneId: "Z2FDTNDATAQYW2" # CloudFront Hosted Zone ID (Static Value)
DNSName: !GetAtt CloudFrontDistribution.DomainName
Route53RecordSetRedirect:
Type: "AWS::Route53::RecordSet"
Properties:
HostedZoneId: !Ref Route53HostedZoneRedirect
Name: !Ref RedirectDomain
Type: "A"
AliasTarget:
HostedZoneId: "Z2FDTNDATAQYW2" # CloudFront Hosted Zone ID (Static Value)
DNSName: !GetAtt CloudFrontDistribution.DomainName
Outputs:
WebsiteURL:
Description: "URL of the primary website"
Value: !Sub "https://${BucketName}"