forked from stelligent/mu-cloudfront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elb.yml
181 lines (181 loc) · 5.36 KB
/
elb.yml
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
Parameters:
DynamicPrefix:
Type: String
Description: Prefix to use for dynamic resources
Default: /api
CloudFrontCert:
Type: String
Description: The identifier for the certificate to use for CloudFront. Leave blank to disable HTTPS
Default: ''
Conditions:
HasCloudFrontCert:
"Fn::Not":
- "Fn::Equals":
- !Ref CloudFrontCert
- ''
Resources:
SiteBucket:
Type: AWS::S3::Bucket
Properties:
BucketName:
Fn::Sub: ${AWS::StackName}-${AWS::Region}-${AWS::AccountId}
SampleBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: SiteBucket
PolicyDocument:
Statement:
- Effect: Allow
Principal:
CanonicalUser:
Fn::Sub: ${CloudFrontOAI.S3CanonicalUserId}
Action: s3:GetObject
Resource:
Fn::Sub: arn:aws:s3:::${SiteBucket}/*
LoggingBucket:
Type: AWS::S3::Bucket
Properties:
BucketName:
Fn::Sub: ${AWS::StackName}-logging-${AWS::Region}-${AWS::AccountId}
CloudFrontOAI:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment:
Fn::Sub: ${AWS::StackName}-logging-${AWS::Region}-${AWS::AccountId}
CloudFrontDist:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Aliases:
- Fn::If:
- HasElbDomainName
- Fn::If:
- HasElbHostName
- Fn::Sub: ${ElbHostName}.${ElbDomainName}
- Fn::Sub: ${ElbDomainName}
- Ref: AWS::NoValue
CustomErrorResponses:
- ErrorCode: 403
ResponseCode: 200
ResponsePagePath: /index.html
CacheBehaviors:
- AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
DefaultTTL: 0
ForwardedValues:
QueryString: true
Cookies:
Forward: all
Headers:
- '*'
MaxTTL: 60
MinTTL: 0
PathPattern:
Fn::Sub: ${DynamicPrefix}/*
TargetOriginId: ecs-alb
ViewerProtocolPolicy:
Fn::If:
- HasCloudFrontCert
- redirect-to-https
- allow-all
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
DefaultTTL: 0
ForwardedValues:
QueryString: no
Cookies:
Forward: all
MaxTTL: 60
MinTTL: 0
TargetOriginId: s3-bucket
ViewerProtocolPolicy:
Fn::If:
- HasCloudFrontCert
- redirect-to-https
- allow-all
DefaultRootObject: index.html
Enabled: true
Logging:
Bucket:
Fn::Sub: ${LoggingBucket.DomainName}
Prefix: cloudfront
Origins:
- Id: s3-bucket
DomainName:
Fn::Sub: ${SiteBucket.DomainName}
S3OriginConfig:
OriginAccessIdentity:
Fn::Sub: origin-access-identity/cloudfront/${CloudFrontOAI}
- Id: ecs-alb
CustomOriginConfig:
HTTPPort: 80
HTTPSPort:
Fn::If:
- HasElbCert
- 443
- Ref: AWS::NoValue
OriginProtocolPolicy:
Fn::If:
- HasElbCert
- https-only
- http-only
OriginSSLProtocols:
- 'TLSv1.2'
DomainName:
Fn::If:
- HasElbDomainName
- Fn::If:
- HasElbHostName
- Fn::Sub: elb.${ElbHostName}.${ElbDomainName}
- Fn::Sub: elb.${ElbDomainName}
- Fn::Sub: ${Elb.DNSName}
PriceClass: PriceClass_100
ViewerCertificate:
Fn::If:
- HasCloudFrontCert
- AcmCertificateArn:
Fn::Sub: "arn:aws:acm:us-east-1:${AWS::AccountId}:certificate/${CloudFrontCert}"
MinimumProtocolVersion: TLSv1.2_2018
SslSupportMethod: sni-only
- Ref: AWS::NoValue
ElbDns:
Properties:
Comment: DNS for CloudFrontDistribution
RecordSets:
Fn::Splice:
- 0
- 2
- - AliasTarget:
HostedZoneId: Z2FDTNDATAQYW2
DNSName:
Fn::GetAtt: CloudFrontDist.DomainName
EvaluateTargetHealth: false
Name:
Fn::If:
Fn::Replace:
- HasElbHostName
- Fn::Sub: ${ElbHostName}.${ElbDomainName}.
- Fn::Sub: ${ElbDomainName}.
- AliasTarget:
HostedZoneId:
Fn::GetAtt: Elb.CanonicalHostedZoneID
DNSName:
Fn::GetAtt: Elb.DNSName
EvaluateTargetHealth: true
Name:
Fn::If:
Fn::Replace:
- HasElbHostName
- Fn::Sub: '*.${ElbHostName}.${ElbDomainName}.'
- Fn::Sub: '*.${ElbDomainName}.'