-
Notifications
You must be signed in to change notification settings - Fork 3
/
serverless-distribution.yml
83 lines (76 loc) · 2.54 KB
/
serverless-distribution.yml
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
service: angular-lambda-ssr-distribution
provider:
name: aws
region: us-east-1
resources:
Resources:
# the origin Identity that we will use in S3, to only allow a specific cloudfront distribution
# access to the S3 content, to keep S3 private
CloudFrontIdentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: cf-accessidentity
# the cloudfront distribution
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
DefaultCacheBehavior:
ForwardedValues:
QueryString: true
Cookies:
Forward: none
TargetOriginId: S3
Compress: true
ViewerProtocolPolicy: redirect-to-https
MaxTTL: 86400
DefaultTTL: 86400
MinTTL: 86400
DefaultRootObject: index.html
HttpVersion: http2
Enabled: true
IPV6Enabled: true
PriceClass: PriceClass_All
Origins:
- DomainName: !Join
- ''
- - !Ref MyS3Bucket
- .s3.amazonaws.com
S3OriginConfig:
OriginAccessIdentity: !Sub 'origin-access-identity/cloudfront/${CloudFrontIdentity}'
Id: S3
CustomErrorResponses:
- ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /index.html
ErrorCachingMinTTL: 300
- ErrorCode: 403
ResponseCode: 200
ResponsePagePath: /index.html
ErrorCachingMinTTL: 300
# the S3 bucket we will use to upload our application (the dist folder)
MyS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: replacewithyourbucketname
# the policy that grants access to S3 to only the cloudfront origin identity
MyS3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref MyS3Bucket
PolicyDocument:
Statement:
Effect: "Allow"
Principal:
AWS: !Sub "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ${CloudFrontIdentity}"
Action: "s3:GetObject"
Resource: !Join
- ''
- - 'arn:aws:s3:::'
- !Ref MyS3Bucket
- /*
Outputs:
CloudFrontEndpoint:
Description: Endpoint for Cloudfront Distribution
Value: !GetAtt CloudFrontDistribution.DomainName