generated from ExamProCo/aws-bootcamp-cruddur-2023
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
101 lines (99 loc) · 3.69 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
AWSTemplateFormatVersion: 2010-09-09
Description: |
- CloudFront Distribution
- S3 Bucket for www.
- S3 Bucket for naked domain
- Bucket Policy
Parameters:
CertificateArn:
Type: String
WwwBucketName:
Type: String
RootBucketName:
Type: String
Resources:
RootBucketPolicy:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref RootBucket
PolicyDocument:
Statement:
- Action:
- 's3:GetObject'
Effect: Allow
Resource: !Sub 'arn:aws:s3:::${RootBucket}/*'
Principal: '*'
WWWBucket:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref WwwBucketName
WebsiteConfiguration:
RedirectAllRequestsTo:
HostName: !Ref RootBucketName
RootBucket:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html
Type: AWS::S3::Bucket
#DeletionPolicy: Retain
Properties:
BucketName: !Ref RootBucketName
PublicAccessBlockConfiguration:
BlockPublicPolicy: false
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: error.html
RootBucketDomain:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset.html
Type: AWS::Route53::RecordSet
Properties:
HostedZoneName: !Sub ${RootBucketName}.
Name: !Sub ${RootBucketName}.
Type: A
AliasTarget:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget.html#cfn-route53-aliastarget-hostedzoneid
# Specify Z2FDTNDATAQYW2. This is always the hosted zone ID when you create an alias record that routes traffic to a CloudFront distribution.
DNSName: !GetAtt Distribution.DomainName
HostedZoneId: Z2FDTNDATAQYW2
WwwBucketDomain:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset.html
Type: AWS::Route53::RecordSet
Properties:
HostedZoneName: !Sub ${RootBucketName}.
Name: !Sub ${WwwBucketName}.
Type: A
AliasTarget:
DNSName: !GetAtt Distribution.DomainName
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget.html#cfn-route53-aliastarget-hostedzoneid
# Specify Z2FDTNDATAQYW2. This is always the hosted zone ID when you create an alias record that routes traffic to a CloudFront distribution.
HostedZoneId: Z2FDTNDATAQYW2
Distribution:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-distribution.html
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Aliases:
- cruddurcorecodecmdsystems.website
- www.cruddurcorecodecmdsystems.website
Comment: Frontend React Js for Cruddur
Enabled: true
HttpVersion: http2and3
DefaultRootObject: index.html
Origins:
- DomainName: !GetAtt RootBucket.DomainName
Id: RootBucketOrigin
S3OriginConfig: {}
DefaultCacheBehavior:
TargetOriginId: RootBucketOrigin
ForwardedValues:
QueryString: false
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
ViewerCertificate:
AcmCertificateArn: !Ref CertificateArn
SslSupportMethod: sni-only
CustomErrorResponses:
- ErrorCode: 403
ResponseCode: 200
ResponsePagePath: /index.html