-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.yaml
209 lines (186 loc) · 6.2 KB
/
template.yaml
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: "EC API app: Lambda, API Gateway"
Globals:
Function:
Timeout: 10
Api:
BinaryMediaTypes:
- "*/*"
Parameters:
AppSecretKey:
Description: "The SECRET_KEY environment variable passed to the app."
Type: String
AppSentryDSN:
Description: "The SENTRY_DSN environment variable passed to the app."
Type: String
GitHash:
Description: "The Hash of the git commit that's deployed"
Type: String
AppDjangoSettingsModule:
# NB This parameter (and how it reaches the app, and how it's set in
# developer and CI-managed deployments) is used in
# `docs/new-development-deployment.md` as a reference to demonstrate how to
# communicate variables to the app. If you modify this parameter, or remove
# it, please update the document so developers aren't left without
# guidance!
Description: "The DJANGO_SETTINGS_MODULE environment variable passed to the app."
Type: String
AppIsBehindCloudFront:
Description: "The APP_IS_BEHIND_CLOUDFRONT environment variable passed to the app, which modifies various path- and host-related settings."
Type: String
AllowedValues:
- "True"
- "False"
Default: "False"
AppLogRetentionDays:
Description: "The number of days that CloudWatch Logs will keep logs from the app."
Type: Number
Default: 60
AllowedValues: [ 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653 ]
AppPostgresHost:
Description: "The Postgres database host for this deploy."
Type: String
AppPostgresDatabaseName:
Description: "The Postgres database name for this deploy."
Type: String
AppPostgresPassword:
Description: "The password for the postgres user"
Type: String
AppWidgetS3URL:
Description: "The URL to the widget JS"
Type: String
AppSamLambdaConfigEnv:
Description: "The lambda config environment passed to the app used to init sentry."
Type: String
AppDomain:
Description: "The domain the app is on."
Type: String
AppLoggerArn:
Default: AppLoggerArn
Description: "The ARN of the Lambda function to log to"
Type: AWS::SSM::Parameter::Value<String>
DevsDCApiKey:
Default: DevsDCApiKey
Description: "The API to use to authenticate to devs.DC"
Type: AWS::SSM::Parameter::Value<String>
Resources:
DependenciesLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: ./lambda-layers/DependenciesLayer/
CompatibleRuntimes:
- python3.12
Metadata:
BuildMethod: python3.12
RetentionPolicy: Delete
ECApiFunction:
Type: AWS::Serverless::Function
Properties:
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/ECApiLambdaExecutionRole"
CodeUri: .
Handler: ec_api.lambda_awsgi.lambda_handler
Layers:
- !Ref DependenciesLayer
Runtime: python3.12
MemorySize: 1024
Environment:
Variables:
SECRET_KEY: !Ref AppSecretKey
SENTRY_DSN: !Ref AppSentryDSN
GIT_HASH: !Ref GitHash
DJANGO_SETTINGS_MODULE: !Ref AppDjangoSettingsModule
APP_IS_BEHIND_CLOUDFRONT: !Ref AppIsBehindCloudFront
POSTGRES_HOST: !Ref AppPostgresHost
POSTGRES_DATABASE_NAME: !Ref AppPostgresDatabaseName
POSTGRES_PASSWORD: !Ref AppPostgresPassword
WIDGET_S3_URL: !Ref AppWidgetS3URL
SAM_LAMBDA_CONFIG_ENV: !Ref AppSamLambdaConfigEnv
APP_DOMAIN: !Ref AppDomain
LOGGER_ARN: !Ref AppLoggerArn
Events:
HTTPRequests:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
HTTPRequestRoots:
Type: Api
Properties:
Path: /
Method: ANY
ECApiFunctionLogGroup:
Type: AWS::Logs::LogGroup
DependsOn: [ ECApiFunction ]
Properties:
LogGroupName: !Sub /aws/lambda/${ECApiFunction}
RetentionInDays: !Ref AppLogRetentionDays
ECAPI:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Cors:
AllowMethods: "'GET'"
AllowOrigin: "'*'"
MaxAge: "'600'"
Auth:
DefaultAuthorizer: APIAuthFunction
Authorizers:
APIAuthFunction:
FunctionArn: !GetAtt APIAuthFunction.Arn
FunctionPayloadType: REQUEST
Identity:
QueryStrings:
- token
ReauthorizeEvery: 3600
APIAuthFunction:
Type: AWS::Serverless::Function
Properties:
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/ECApiLambdaExecutionRole"
CodeUri: ./api_endpoints/api_auth
Handler: handler.lambda_handler
AutoPublishAlias: live
Environment:
Variables:
POSTGRES_HOST: !Ref AppPostgresHost
POSTGRES_DATABASE_NAME: !Ref AppPostgresDatabaseName
POSTGRES_PASSWORD: !Ref AppPostgresPassword
Runtime: python3.12
V1VotingInformationFunction:
Type: AWS::Serverless::Function
Properties:
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/ECApiLambdaExecutionRole"
CodeUri: ./api_endpoints/v1_postcode_lookup/
Handler: app.handler
AutoPublishAlias: live
Runtime: python3.12
MemorySize: 512
Environment:
Variables:
SENTRY_DSN: !Ref AppSentryDSN
DC_API_TOKEN: !Ref DevsDCApiKey
LOGGER_ARN: !Ref AppLoggerArn
Events:
PostcodeRequests:
Type: Api
Properties:
RestApiId: !Ref ECAPI
Path: /api/v1/postcode/{proxy+}
Method: GET
AddressRequests:
Type: Api
Properties:
RestApiId: !Ref ECAPI
Path: /api/v1/address/{proxy+}
Method: GET
Outputs:
ECApiFqdn:
Description: "API Gateway endpoint FQDN for EC API function"
Value: !Sub "${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com"
Export:
Name: !Join [ ":", [ !Ref "AWS::StackName", "ECApiFqdn" ] ]
ECStarletteApi:
Description: "API Gateway endpoint FQDN for EC Starlette API function"
Value: !Sub "${ECAPI}.execute-api.${AWS::Region}.amazonaws.com"
Export:
Name: !Join [ ":", [ !Ref "AWS::StackName", "ECStarletteApiFqdn" ] ]