-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy paths3-cloudfront-resources.yml
More file actions
72 lines (68 loc) · 2.66 KB
/
s3-cloudfront-resources.yml
File metadata and controls
72 lines (68 loc) · 2.66 KB
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
Resources:
PhotosBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub '${self:custom.photosBucketName}'
AccessControl: Private
CorsConfiguration:
CorsRules:
- AllowedHeaders: ['*']
AllowedMethods: ['PUT']
AllowedOrigins: ['*']
PhotosBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: PhotosBucket
PolicyDocument:
Statement:
# Read permission for CloudFront
- Action: s3:GetObject
Effect: "Allow"
Resource: !Sub "arn:aws:s3:::#{PhotosBucket}/*"
Principal:
CanonicalUser: !GetAtt CloudFrontOriginAccessIdentity.S3CanonicalUserId
CloudFrontOriginAccessIdentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: !Sub 'Identity for accessing CloudFront from S3 within stack #{AWS::StackName}'
# Cloudfront distro backed by PhotosBucket
PhotosCdnDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
# S3 origin for static content
- DomainName: !Sub '${self:custom.photosBucketName}.s3.amazonaws.com'
Id: PhotosBucketS3Origin
S3OriginConfig:
OriginAccessIdentity: !Sub 'origin-access-identity/cloudfront/#{CloudFrontOriginAccessIdentity}'
Enabled: true
Comment: CDN for photos.
DefaultRootObject: index.html
HttpVersion: http2
DefaultCacheBehavior:
AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
Compress: true
TargetOriginId: PhotosBucketS3Origin
ForwardedValues:
QueryString: false
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
PriceClass: PriceClass_200
Outputs:
PhotosBucket:
Value: !Ref PhotosBucket
PhotosCdnDistributionId:
Value: !Ref PhotosCdnDistribution
PhotosCdnDistributionDomainName:
Value: !GetAtt PhotosCdnDistribution.DomainName