-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.yml
More file actions
229 lines (214 loc) · 6.78 KB
/
serverless.yml
File metadata and controls
229 lines (214 loc) · 6.78 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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
org: photonadmin # Corresponds to the serverless.com account used for monitoring
app: photonranch
service: photonranch-projects
package:
patterns:
- '!venv/**'
- '!node_modules/**'
plugins:
- serverless-python-requirements
- serverless-dynamodb-pitr
- serverless-domain-manager
custom:
# define the name for the projects dynamodb table
projectsTable: projects-${self:provider.stage}
# Enable point-in-time-recovery
pitr:
- tableName: ${self:custom.projectsTable}
enabled: true
# This is the 'variable' for the customDomain.basePath value, based on the stage.
# Run as `sls deploy --stage <stage_name>`
stage:
prod: projects
dev: dev
test: test
# Since lambda runs on a linux instance, we need to zip the requirements in a linux docker container.
pythonRequirements:
dockerizePip: non-linux
useDownloadCache: false
useStaticCache: false
customDomain:
domainName: 'projects.photonranch.org'
basePath: ${self:custom.stage.${self:provider.stage}}
stage: ${self:provider.stage}
createRoute53Record: true
provider:
name: aws
stage: ${opt:stage, "test"}
runtime: python3.9
region: us-east-1
environment:
PROJECTS_TABLE: ${self:custom.projectsTable}
AUTH0_CLIENT_ID: ${file(./secrets.json):AUTH0_CLIENT_ID}
AUTH0_CLIENT_PUBLIC_KEY: ${file(./public_key)}
STAGE: ${self:provider.stage}
iam:
role:
statements:
- Effect: Allow
Action:
- "dynamodb:PutItem"
- "dynamodb:GetItem"
- "dynamodb:UpdateItem"
- "dynamodb:DeleteItem"
- "dynamodb:Scan"
- "dynamodb:Query"
Resource:
- "arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.PROJECTS_TABLE}*"
resources: # CloudFormation template syntax from here on.
Resources:
# Configure API gateway "Gateway Responses" to work with CORS restrictions
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
gatewayresponse.header.Access-Control-Allow-Methods: "'GET,POST,OPTIONS'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
GatewayResponseDefault5XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
gatewayresponse.header.Access-Control-Allow-Methods: "'GET,POST,OPTIONS'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
GatewayResponse:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: EXPIRED_TOKEN
RestApiId:
Ref: 'ApiGatewayRestApi'
StatusCode: '401'
AuthFailureGatewayResponse:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: UNAUTHORIZED
RestApiId:
Ref: 'ApiGatewayRestApi'
StatusCode: '401'
# Define the dynamodb table we use to store projects
projectsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.projectsTable}
AttributeDefinitions:
- AttributeName: project_name
AttributeType: S
- AttributeName: user_id
AttributeType: S
- AttributeName: created_at
AttributeType: S
#- AttributeName: site
#AttributeType: S
#- AttributeName: creator_id
#AttributeType: S
KeySchema:
- AttributeName: project_name
KeyType: HASH
- AttributeName: created_at
KeyType: RANGE
GlobalSecondaryIndexes:
- IndexName: userid-createdat-index
KeySchema:
- AttributeName: user_id
KeyType: HASH
- AttributeName: created_at
KeyType: RANGE
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
functions:
authorizerFunc:
handler: authorizer.auth
addNewProject:
handler: handler.addNewProject
events:
- http:
path: new-project
method: post
#authorizer:
#name: authorizerFunc
#resultTtlInSeconds: 0 # Don't cache the policy or other tasks will fail!
cors: true
modifyProject:
handler: handler.modify_project_handler
events:
- http:
path: modify-project
method: post
cors: true
getProject:
handler: handler.get_project_handler
events:
- http:
path: get-project
method: post
#authorizer:
#name: authorizerFunc
#resultTtlInSeconds: 0 # Don't cache the policy or other tasks will fail!
cors: true
addProjectData:
handler: handler.addProjectData
events:
- http:
path: add-project-data
method: post
cors: true
addProjectEvent:
handler: handler.addProjectEvent
events:
- http:
path: add-project-event
method: post
cors: true
deleteProject:
handler: handler.deleteProject
events:
- http:
path: delete-project
method: post
authorizer:
name: authorizerFunc
resultTtlInSeconds: 0 # Don't cache the policy or other tasks will fail!
cors: true
deleteSchedulerProjects:
handler: handler.deleteSchedulerProjects
events:
- http:
path: delete-scheduler-projects
method: post
cors: true
getAllProjects:
handler: handler.getAllProjects
events:
- http:
path: get-all-projects
method: post
cors: true
getUserProjects:
handler: handler.getUserProjects
events:
- http:
path: get-user-projects
method: post
#authorizer:
#name: authorizerFunc
#resultTtlInSeconds: 0 # Don't cache the policy or other tasks will fail!
cors: true