-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
54 lines (42 loc) · 1.34 KB
/
app.py
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
import json
import awsgi
from api.api import app
# TODO: Find a better way of managing this
def cron_event(path):
return {
"version": "1.0",
"resource": "/{proxy+}",
"path": path,
"httpMethod": "GET",
"headers": {
"Content-Length": "0",
"User-Agent": "",
},
"multiValueHeaders": {
"Content-Length": ["0"],
"User-Agent": [""],
},
"queryStringParameters": None,
"multiValueQueryStringParameters": None,
"requestContext": {
"httpMethod": "GET",
"identity": {},
"path": path,
},
"pathParameters": {"proxy": path},
}
def lambda_handler(event, context):
# Handle scheduled internal cron events
if "cron" in event:
return awsgi.response(app, cron_event(event["cron"]), context)
# Handle CloudWatch keep warm events
if "httpMethod" not in event:
return {"statusCode": 200, "body": json.dumps({"message": "warm"})}
# Simple way to block namespaced cron routes
if event.get("path", "").startswith("/cron"):
return {"statusCode": 404, "body": "404: Not found"}
return awsgi.response(
app, event, context, base64_content_types={"application/octet-stream"}
)
if __name__ == "__main__":
app.run(host="0.0.0.0")