-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
executable file
·91 lines (91 loc) · 3.17 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
AWSTemplateFormatVersion: 2010-09-09
Description: >
A cloud formation template that creates a static website that uses a custom domain to server traffic
through a cloud front distribution with website static asserts hosted in an s3 bucket.
Parameters:
DomainName: basicskillshub.com
Type: String
Description: The DNS name of an existing Amazon Route 53 hosted zone e.g kellyaudu.me
AllowedPattern: (?!-)[a-zA-Z0-9-.]{1,63}(?<!-)
ConstraintDescription: must be a valid DNS zone name
FullDomainName: www.basicskillshub.com
Type: String
Description: The full domain name e.g www.kellyaudu.io
AllowedPattern: (?!-)[a-zA-Z0-9-.]{1,63}(?<!-)
ConstraintDescription: must be a valid DNS zone name
AcmCertificateArn: arn:aws:acm:us-east-1:143187677776:certificate/e5d067f6-057c-48c7-87fe-bea1d8705087
Type: String
Description: the Amazon Resource Name (ARN) of an AWS certificate(Certificate must be created in us-east-1 region)
AllowedPattern: "arn:aws:acm:.*"
HostedZoneId:
Type: String
Description: The hosted zone of the domain name
Resources:
WebsiteBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref FullDomainName
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: 404.html
WebsiteBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref WebsiteBucket
PolicyDocument:
Statement:
Effect: Allow
Principal: '*'
Action: S3:GetObject
Resource: !Join ['', ['arn:aws:s3:::', !Ref WebsiteBucket, /*]]
WebsiteCloudFront:
Type: AWS::CloudFront::Distribution
Description: WebsiteBucket
Properties:
DistributionConfig:
Comment: Cloudfront Distribution pointing to s3 bucket for kelly's website
Origins:
- DomainName: !Select [2, !Split ['/', !GetAtt WebsiteBucket.WebsiteURL]]
Id: S3Origin
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: http-only
Enabled: true
HttpVersion: 'http2'
DefaultRootObject: index.html
Aliases:
- !Ref FullDomainName
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
Compress: true
TargetOriginId: S3Origin
ForwardedValues:
QueryString: true
ViewerProtocolPolicy: redirect-to-https
PriceClass: PriceClass_All
ViewerCertificate:
AcmCertificateArn: !Ref AcmCertificateArn
SslSupportMethod: sni-only
WebsiteDNSName:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZoneId
Type: A
Name: !Ref FullDomainName
AliasTarget:
DNSName: !GetAtt WebsiteCloudFront.DomainName
HostedZoneId: !Ref HostedZoneId
Outputs:
BucketName:
Value: !Ref WebsiteBucket
Description: Name of s3 bucket that stores website content
CloudfrontEndPoint:
Value: !GetAtt [WebsiteCloudFront, DomainName]
Description: Endpoint for cloudfront distribution
FullDomainName:
Value: !Ref FullDomainName
Description: Full DomainName