1
|
AWSTemplateFormatVersion: '2010-09-09'
|
2
|
Description: Sample template for S3Origin CloudFront
|
3
|
|
4
|
Parameters:
|
5
|
CloudFrontPriceClass:
|
6
|
Type: String
|
7
|
Default: PriceClass_200
|
8
|
AllowedValues: [PriceClass_100, PriceClass_200, PriceClass_All]
|
9
|
|
10
|
Resources:
|
11
|
|
12
|
OriginS3Bucket:
|
13
|
Type: AWS::S3::Bucket
|
14
|
DeletionPolicy: Retain
|
15
|
UpdateReplacePolicy: Retain
|
16
|
Properties:
|
17
|
BucketName: !Sub ${AWS::StackName}-${AWS::AccountId}
|
18
|
PublicAccessBlockConfiguration:
|
19
|
BlockPublicAcls: True
|
20
|
BlockPublicPolicy: True
|
21
|
IgnorePublicAcls: True
|
22
|
RestrictPublicBuckets: True
|
23
|
|
24
|
OriginS3BucketPolicy:
|
25
|
Type: AWS::S3::BucketPolicy
|
26
|
Properties:
|
27
|
Bucket: !Ref OriginS3Bucket
|
28
|
PolicyDocument:
|
29
|
Statement:
|
30
|
- Action: s3:GetObject
|
31
|
Effect: Allow
|
32
|
Resource: !Sub arn:${AWS::Partition}:s3:::${OriginS3Bucket}/*
|
33
|
Principal:
|
34
|
Service: cloudfront.amazonaws.com
|
35
|
Condition:
|
36
|
StringEquals:
|
37
|
AWS:SourceArn: !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/${CloudFrontDistribution}
|
38
|
- Action: s3:ListBucket
|
39
|
Effect: Allow
|
40
|
Resource: !Sub arn:${AWS::Partition}:s3:::${OriginS3Bucket}
|
41
|
Principal:
|
42
|
Service: cloudfront.amazonaws.com
|
43
|
Condition:
|
44
|
StringEquals:
|
45
|
AWS:SourceArn: !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/${CloudFrontDistribution}
|
46
|
|
47
|
CloudFrontDistribution:
|
48
|
Type: AWS::CloudFront::Distribution
|
49
|
Properties:
|
50
|
DistributionConfig:
|
51
|
Comment: !Sub 'Created by ${AWS::StackName}'
|
52
|
DefaultCacheBehavior:
|
53
|
TargetOriginId: mainS3Origin
|
54
|
ForwardedValues:
|
55
|
QueryString: false
|
56
|
Cookies:
|
57
|
Forward: 'none'
|
58
|
ViewerProtocolPolicy: redirect-to-https
|
59
|
CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6
|
60
|
OriginRequestPolicyId: acba4595-bd28-49b8-b9fe-13317c0390fa
|
61
|
Compress: true
|
62
|
DefaultRootObject: index.html
|
63
|
Enabled: true
|
64
|
Origins:
|
65
|
- DomainName: !Sub ${OriginS3Bucket}.s3.amazonaws.com
|
66
|
Id: mainS3Origin
|
67
|
S3OriginConfig:
|
68
|
OriginAccessIdentity: ''
|
69
|
OriginAccessControlId: !GetAtt OriginAccessControl.Id
|
70
|
PriceClass: !Ref CloudFrontPriceClass
|
71
|
Restrictions:
|
72
|
GeoRestriction:
|
73
|
RestrictionType: whitelist
|
74
|
Locations:
|
75
|
- JP
|
76
|
|
77
|
OriginAccessControl:
|
78
|
Type: AWS::CloudFront::OriginAccessControl
|
79
|
Properties:
|
80
|
OriginAccessControlConfig:
|
81
|
Description: !Sub 'OAC of ${OriginS3Bucket}. Created by ${AWS::StackName}'
|
82
|
Name: !Sub 'OAC-${OriginS3Bucket}'
|
83
|
OriginAccessControlOriginType: s3
|
84
|
SigningBehavior: always
|
85
|
SigningProtocol: sigv4
|
86
|
|
87
|
Outputs:
|
88
|
OriginS3BucketName:
|
89
|
Value: !Ref OriginS3Bucket
|
90
|
Export:
|
91
|
Name: !Sub ${AWS::StackName}-OriginS3Bucket
|
92
|
CloudfrontDomainName:
|
93
|
Value: !GetAtt CloudFrontDistribution.DomainName
|
94
|
Export:
|
95
|
Name: !Sub ${AWS::StackName}-CloudfrontDomainName
|