This repository has been archived by the owner on Aug 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
template.yaml
116 lines (115 loc) · 3.25 KB
/
template.yaml
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
AWSTemplateFormatVersion: '2010-09-09'
Resources:
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
DependsOn:
- S3Bucket
- OriginAccessIdentity
Properties:
DistributionConfig:
Origins:
- DomainName: !GetAtt 'S3Bucket.DomainName'
Id: hostingS3Bucket
S3OriginConfig:
OriginAccessIdentity: !Join
- ''
- - origin-access-identity/cloudfront/
- !Ref 'OriginAccessIdentity'
Enabled: 'true'
DefaultCacheBehavior:
AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
TargetOriginId: hostingS3Bucket
ForwardedValues:
QueryString: 'false'
ViewerProtocolPolicy: redirect-to-https
DefaultTTL: 86400
MaxTTL: 31536000
MinTTL: 60
Compress: true
DefaultRootObject: index.html
CustomErrorResponses:
- ErrorCachingMinTTL: 300
ErrorCode: 400
ResponseCode: 200
ResponsePagePath: /
- ErrorCachingMinTTL: 300
ErrorCode: 403
ResponseCode: 200
ResponsePagePath: /
- ErrorCachingMinTTL: 300
ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /
S3Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
AccessControl: Private
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: index.html
CorsConfiguration:
CorsRules:
- AllowedHeaders:
- Authorization
- Content-Length
AllowedMethods:
- GET
AllowedOrigins:
- '*'
MaxAge: 3000
PrivateBucketPolicy:
Type: AWS::S3::BucketPolicy
DependsOn: OriginAccessIdentity
Properties:
PolicyDocument:
Id: MyPolicy
Version: '2012-10-17'
Statement:
- Sid: APIReadForGetBucketObjects
Effect: Allow
Principal:
CanonicalUser: !GetAtt 'OriginAccessIdentity.S3CanonicalUserId'
Action: s3:GetObject
Resource: !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- /*
Bucket: !Ref 'S3Bucket'
OriginAccessIdentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: CloudFrontOriginAccessIdentityConfig
Outputs:
Region:
Value: !Ref 'AWS::Region'
HostingBucketName:
Description: Hosting bucket name
Value: !Ref 'S3Bucket'
WebsiteURL:
Value: !GetAtt 'S3Bucket.WebsiteURL'
Description: URL for website hosted on S3
S3BucketSecureURL:
Value: !Join
- ''
- - https://
- !GetAtt 'S3Bucket.DomainName'
Description: Name of S3 bucket to hold website content
CloudFrontDistributionID:
Value: !Ref 'CloudFrontDistribution'
CloudFrontDomainName:
Value: !GetAtt 'CloudFrontDistribution.DomainName'
CloudFrontSecureURL:
Value: !Join
- ''
- - https://
- !GetAtt 'CloudFrontDistribution.DomainName'