-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.cfn.yaml
103 lines (95 loc) · 2.95 KB
/
template.cfn.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
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
Env:
Type: 'String'
Default: 'prod'
Conditions:
IsProd: !Equals
- !Ref Env
- 'prod'
Resources:
S3Bucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Sub "cars-fe-${Env}"
PublicAccessBlockConfiguration:
BlockPublicAcls : true
BlockPublicPolicy : true
IgnorePublicAcls : true
RestrictPublicBuckets : true
VersioningConfiguration:
Status: Suspended
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: 'AES256'
BucketPolicy:
Type: 'AWS::S3::BucketPolicy'
Properties:
PolicyDocument:
Id: MyPolicy
Version: 2012-10-17
Statement:
- Sid: PolicyForCloudFrontPrivateContent
Effect: Allow
Principal:
CanonicalUser: !GetAtt CFOriginAccessIdentity.S3CanonicalUserId
Action: 's3:GetObject*'
Resource: !Join
- ''
- - 'arn:aws:s3:::'
- !Ref S3Bucket
- /*
Bucket: !Ref S3Bucket
CFDistribution:
Type: 'AWS::CloudFront::Distribution'
DependsOn:
- CFOriginAccessIdentity
Properties:
DistributionConfig:
Origins:
- DomainName: !GetAtt S3Bucket.RegionalDomainName
Id: myS3Origin
S3OriginConfig:
OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${CFOriginAccessIdentity}"
Enabled: 'true'
DefaultRootObject: index.html
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: myS3Origin
CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6 # CachingOptimized
OriginRequestPolicyId: 88a5eaf4-2fd4-4709-b370-b4c650ea3fcf # CORS-S3Origin
ViewerProtocolPolicy: redirect-to-https
PriceClass: PriceClass_100
ViewerCertificate:
AcmCertificateArn: "arn:aws:acm:us-east-1:428124435373:certificate/c8de19e7-c3f9-44de-9d3c-563e5fa91796"
SslSupportMethod: 'sni-only'
MinimumProtocolVersion: 'TLSv1.2_2021'
Aliases:
- !Sub
- "${Prefix}cars.foacs.fr"
- Prefix: !If [ IsProd, '', !Sub "${Env}." ]
CFOriginAccessIdentity:
Type: 'AWS::CloudFront::CloudFrontOriginAccessIdentity'
DependsOn:
- S3Bucket
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: !Sub "access-identity-cars-fe-${Env}"
Route53:
Type: 'AWS::Route53::RecordSet'
DependsOn:
- CFDistribution
Properties:
HostedZoneId: Z09666831AUBN0E7PSDUV
AliasTarget:
DNSName: !GetAtt CFDistribution.DomainName
EvaluateTargetHealth: false
HostedZoneId: Z2FDTNDATAQYW2
Name: !Sub
- "${Prefix}cars.foacs.fr."
- Prefix: !If [IsProd, '', !Sub "${Env}."]
Type: A