-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Expand file tree
/
Copy pathStaticS3CloudFront.yml
More file actions
161 lines (144 loc) · 3.91 KB
/
Copy pathStaticS3CloudFront.yml
File metadata and controls
161 lines (144 loc) · 3.91 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
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
AWSTemplateFormatVersion: '2010-09-09'
Description: >
Creates the following resources:
- An S3 bucket for the website
- A CloudFront for serving the static assets
Parameters:
CertificateArn:
Type: String
Description: The ARN of the SSL Certificate for Remix
FQDN:
Type: String
Description: The desired FQDN of the website
EnvType:
Type: String
Description: The type of environment to create.
Default: dev
AllowedValues:
- dev
- prod
ConstraintDescription: must specify prod or dev.
Mappings:
CacheSettings:
dev:
DefaultTTL: 0
prod:
DefaultTTL: 86400
Resources:
OriginAccessIdentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: !Sub Static assets in ${AWS::StackName}
WebBucket:
Type: AWS::S3::Bucket
Properties:
LoggingConfiguration:
DestinationBucketName: !Ref LogBucket
LogFilePrefix: !If
- NoFQDN
- !Sub s3/${AWS::StackName}/
- !Sub s3/${FQDN}/
WebBucketPolicy:
Type: AWS::S3::BucketPolicy
DependsOn: OriginAccessIdentity
Properties:
Bucket: !Ref WebBucket
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource: !Join
- ""
- - !GetAtt WebBucket.Arn
- "/*"
Principal:
CanonicalUser: !GetAtt OriginAccessIdentity.S3CanonicalUserId
Distribution:
Type: AWS::CloudFront::Distribution
DependsOn: OriginAccessIdentity
Properties:
DistributionConfig:
Enabled: true
HttpVersion: http2
PriceClass: PriceClass_100
ViewerCertificate: !If
- NoSSL
- !Ref AWS::NoValue
- AcmCertificateArn: !Ref CertificateArn
MinimumProtocolVersion: TLSv1.1_2016
SslSupportMethod: sni-only
Comment: !If
- NoFQDN
- !Ref AWS::NoValue
- !Ref FQDN
Aliases: !If
- NoFQDN
- !Ref AWS::NoValue
- - !Ref FQDN
DefaultRootObject: index.html
DefaultCacheBehavior:
ForwardedValues:
QueryString: false
AllowedMethods:
- HEAD
- GET
- OPTIONS
Compress: true
DefaultTTL: !FindInMap [CacheSettings, !Ref EnvType, "DefaultTTL"]
ViewerProtocolPolicy: !If
- NoSSL
- allow-all
- redirect-to-https
TargetOriginId: Bucket
Origins:
- Id: Bucket
DomainName: !GetAtt WebBucket.DomainName
S3OriginConfig:
OriginAccessIdentity: !Join
- /
- - origin-access-identity
- cloudfront
- !Ref OriginAccessIdentity
Logging:
Bucket: !Join
- .
- - !Ref LogBucket
- s3
- !Ref AWS::URLSuffix
Prefix: !If
- NoFQDN
- !Sub web/${AWS::StackName}/
- !Sub web/${FQDN}/
IncludeCookies: true
LogBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: LogDeliveryWrite
VersioningConfiguration:
Status: Suspended
LifecycleConfiguration:
Rules:
- Status: Enabled
ExpirationInDays: 3653
NoncurrentVersionExpirationInDays: 1
SharedLogGroup:
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: 7
LogGroupName: !Join [ '-', [ !Ref 'AWS::StackName', 'LogGroup']]
Conditions:
NoFQDN: !Equals
- !Ref FQDN
- ''
NoSSL: !Equals
- !Ref CertificateArn
- ''
Outputs:
WebBucketArn:
Description: ARN of S3 bucket hosting the website
Value: !GetAtt WebBucket.Arn
Export:
Name: !Sub '${AWS::StackName}WebBucketArn'