-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathexodus-lambda-deploy.yaml
More file actions
136 lines (124 loc) · 3.85 KB
/
Copy pathexodus-lambda-deploy.yaml
File metadata and controls
136 lines (124 loc) · 3.85 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: Configuration for exodus-cdn Lambda@Edge deployment
Parameters:
env:
Type: String
AllowedValues:
- dev
- stage
- prod
Default: dev
Description: The environment for which resources are intended
oai:
Type: String
Description: The origin access identity ID associated with the environment
project:
Type: String
Default: exodus
Description: The project name under which resources are created
lambdafunctionrole:
Type: String
Default: None
Description: The IAM Role ARN for Lambda Function resource
keyids:
Type: CommaDelimitedList
Default: None
Description: A list of secret key IDs for Distribution key groups
Conditions:
EnableKeyGroup:
!Not [!Equals [!Join ["", !Ref keyids], None]]
Resources:
KeyGroup:
Type: AWS::CloudFront::KeyGroup
Condition: EnableKeyGroup
Properties:
KeyGroupConfig:
Name: !Sub ${project}-cdn-${env}
Comment: !Sub Signed URLs and cookies for ${project}-cdn-${env}
Items: !Ref keyids
CachePolicy:
Type: AWS::CloudFront::CachePolicy
Properties:
CachePolicyConfig:
DefaultTTL: 86400
MaxTTL: 31536000
MinTTL: 0
Name: !Sub ${project}-cache-policy-${env}
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: whitelist
Cookies:
- CloudFront-Key-Pair-Id
- CloudFront-Policy
- CloudFront-Signature
EnableAcceptEncodingGzip: false
HeadersConfig:
HeaderBehavior: whitelist
Headers:
- Want-Digest
- X-Exodus-Query
QueryStringsConfig:
QueryStringBehavior: none
Distribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Comment: !Sub ${project}-cdn-${env}
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
CachedMethods:
- GET
- HEAD
CachePolicyId: !Ref CachePolicy
LambdaFunctionAssociations:
- EventType: origin-request
LambdaFunctionARN: !Ref OriginRequestFunc.Version
- EventType: origin-response
LambdaFunctionARN: !Ref OriginResponseFunc.Version
TargetOriginId: !Sub S3-${project}-cdn-${env}
TrustedKeyGroups:
- !If
- EnableKeyGroup
- !Ref KeyGroup
- !Ref AWS::NoValue
ViewerProtocolPolicy: redirect-to-https
Enabled: true
HttpVersion: http2
Origins:
- DomainName: !Sub "${project}-cdn-${env}.s3.amazonaws.com"
Id: !Sub "S3-${project}-cdn-${env}"
S3OriginConfig:
OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${oai}"
OriginRequestFunc:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${project}-origin-request-${env}
CodeUri:
Handler: exodus_lambda.origin_request
Role: !Sub ${lambdafunctionrole}
Runtime: python3.9
Timeout: 5
AutoPublishAlias: live
OriginResponseFunc:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${project}-origin-response-${env}
CodeUri:
Handler: exodus_lambda.origin_response
Role: !Sub ${lambdafunctionrole}
Runtime: python3.9
Timeout: 5
AutoPublishAlias: live
Outputs:
Distribution:
Description: distribution domain name
Value: !GetAtt Distribution.DomainName
OriginRequestFunc:
Description: origin-request function ARN with version
Value: !Ref OriginRequestFunc.Version
OriginResponseFunc:
Description: origin-response function ARN with version
Value: !Ref OriginResponseFunc.Version