-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcfn.yaml
More file actions
81 lines (78 loc) · 2.18 KB
/
Copy pathcfn.yaml
File metadata and controls
81 lines (78 loc) · 2.18 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
AWSTemplateFormatVersion: 2010-09-09
Parameters:
DomainName:
Description: 'Domain name of the CDN, e.g. assets.example.com'
Type: String
CFCertificate:
Description: 'Existing ACM Certificate ARN for CloudFront. Must be created in the us-east-1 region!'
Type: String
ForceHttps:
Type: String
Description: Force HTTPS by redirecting HTTP requests
Default: '0'
AllowedValues:
- 0
- 1
Conditions:
HasForceHttps: !Equals [ !Ref ForceHttps, '1' ]
Resources:
AssetsBucket:
Type: 'AWS::S3::Bucket'
Properties:
WebsiteConfiguration:
IndexDocument: 'index.html'
S3BucketPolicy:
Type: 'AWS::S3::BucketPolicy'
Properties:
Bucket: !Ref AssetsBucket
PolicyDocument:
Statement:
- Action:
- 's3:GetObject'
Effect: Allow
Resource:
- !Sub 'arn:aws:s3:::${AssetsBucket}/*'
Principal: '*'
- Action:
- 's3:ListBucket'
Effect: Allow
Resource:
- !GetAtt 'AssetsBucket.Arn'
Principal: '*'
AssetsCDN:
Type: 'AWS::CloudFront::Distribution'
Properties:
DistributionConfig:
Origins:
- DomainName: !GetAtt
- AssetsBucket
- DomainName
Id: AssetsBucket
S3OriginConfig: {}
Enabled: true
HttpVersion: http2
Aliases:
- !Ref DomainName
DefaultCacheBehavior:
ForwardedValues:
QueryString: false
Cookies:
Forward: none
TargetOriginId: AssetsBucket
ViewerProtocolPolicy: !If [HasForceHttps, 'redirect-to-https', 'allow-all']
ViewerCertificate:
AcmCertificateArn: !Ref CFCertificate
SslSupportMethod: sni-only
PriceClass: PriceClass_100
CustomErrorResponses:
- ErrorCode: 404
ResponseCode: 200
ResponsePagePath: '/index.html'
DefaultRootObject: 'index.html'
Outputs:
AssetsBucket:
Value: !Ref AssetsBucket
CloudFrontDistribution:
Value: !Ref AssetsCDN
CloudFrontDomainName:
Value: !GetAtt 'AssetsCDN.DomainName'