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
|
AccessControl: Private
|
19
|
PublicAccessBlockConfiguration:
|
20
|
BlockPublicAcls: True
|
21
|
BlockPublicPolicy: True
|
22
|
IgnorePublicAcls: True
|
23
|
RestrictPublicBuckets: True
|
24
|
|
25
|
OriginS3BucketPolicy:
|
26
|
Type: AWS::S3::BucketPolicy
|
27
|
Properties:
|
28
|
Bucket: !Ref OriginS3Bucket
|
29
|
PolicyDocument:
|
30
|
Statement:
|
31
|
- Action:
|
32
|
- s3:GetObject
|
33
|
Effect: Allow
|
34
|
Resource: !Sub arn:${AWS::Partition}:s3:::${OriginS3Bucket}/*
|
35
|
Principal:
|
36
|
AWS: !Sub arn:${AWS::Partition}:iam::cloudfront:user/CloudFront Origin Access Identity ${OriginAccessIdentity}
|
37
|
- Action:
|
38
|
- s3:ListBucket
|
39
|
Effect: Allow
|
40
|
Resource: !Sub arn:${AWS::Partition}:s3:::${OriginS3Bucket}
|
41
|
Principal:
|
42
|
AWS: !Sub arn:${AWS::Partition}:iam::cloudfront:user/CloudFront Origin Access Identity ${OriginAccessIdentity}
|
43
|
|
44
|
CloudFrontDistribution:
|
45
|
Type: AWS::CloudFront::Distribution
|
46
|
Properties:
|
47
|
DistributionConfig:
|
48
|
Comment: !Sub "Created by ${AWS::StackName}"
|
49
|
DefaultCacheBehavior:
|
50
|
TargetOriginId: myS3Origin
|
51
|
ForwardedValues:
|
52
|
QueryString: false
|
53
|
Cookies:
|
54
|
Forward: 'none'
|
55
|
ViewerProtocolPolicy: redirect-to-https
|
56
|
Compress: true
|
57
|
DefaultRootObject: index.html
|
58
|
Enabled: true
|
59
|
Origins:
|
60
|
- DomainName: !Sub ${OriginS3Bucket}.s3.amazonaws.com
|
61
|
Id: myS3Origin
|
62
|
S3OriginConfig:
|
63
|
OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${OriginAccessIdentity}"
|
64
|
PriceClass: !Ref CloudFrontPriceClass
|
65
|
Restrictions:
|
66
|
GeoRestriction:
|
67
|
RestrictionType: whitelist
|
68
|
Locations:
|
69
|
- JP
|
70
|
|
71
|
OriginAccessIdentity:
|
72
|
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
|
73
|
Properties:
|
74
|
CloudFrontOriginAccessIdentityConfig:
|
75
|
Comment: !Sub "Created by ${AWS::StackName}"
|
76
|
|
77
|
Outputs:
|
78
|
OriginS3BucketName:
|
79
|
Value: !Ref OriginS3Bucket
|
80
|
Export:
|
81
|
Name: !Sub ${AWS::StackName}-OriginS3Bucket
|
82
|
CloudfrontDomainName:
|
83
|
Value: !GetAtt CloudFrontDistribution.DomainName
|
84
|
Export:
|
85
|
Name: !Sub ${AWS::StackName}-CloudfrontDomainName
|