-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlambda_function.py
More file actions
32 lines (25 loc) · 845 Bytes
/
Copy pathlambda_function.py
File metadata and controls
32 lines (25 loc) · 845 Bytes
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
import json
from contextlib import suppress
from core import build_print_options, generate_pdf
def handler(event, context):
params = {}
with suppress(Exception):
parsed = json.loads(event["body"])
params = parsed if isinstance(parsed, dict) else {}
source = params.get("source")
if source is None:
return {
"statusCode": 400,
"body": json.dumps({"error": "source is required"}),
}
if isinstance(params.get("print_options"), dict):
print_options = build_print_options(params.get("print_options"))
else:
print_options = build_print_options()
pdf = generate_pdf(source, print_options)
return {
"statusCode": 201,
"headers": {"Content-Type": "application/pdf"},
"body": pdf,
"isBase64Encoded": True,
}