forked from tstachlewski/serverless-survey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
survey_submit.py
49 lines (38 loc) · 1.16 KB
/
survey_submit.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
from yattag import Doc
import uuid
import boto3
import os
import json
def lambda_handler(event, context):
ItemData = {}
ItemData['id'] = str(uuid.uuid4())
for param in event["queryStringParameters"]:
value = event["queryStringParameters"][param]
if not value:
value = "-"
ItemData[param] = value
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(os.environ['TABLE_NAME'])
table.put_item(
Item = ItemData
)
doc, tag, text = Doc().tagtext()
with tag('html'):
with tag('body'):
with tag('div', align='center'):
with tag('h1'):
doc.stag('br')
doc.stag('br')
doc.stag('br')
doc.stag('br')
doc.stag('br')
doc.stag('br')
text("Your answers were submitted! Thank you!")
htmlResult = doc.getvalue()
return {
'statusCode': "200",
'body': htmlResult,
'headers': {
'Content-Type': 'text/html',
}
}