-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.py
More file actions
39 lines (34 loc) · 1.02 KB
/
lambda.py
File metadata and controls
39 lines (34 loc) · 1.02 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
import json
import boto3
import secrets
import time
import datetime
# Lambda with Gateway trigger and DynamoDB Destination
# Take in data from form and process it to be put into database tables
def lambda_handler(event, context):
# build custom id
secretsGenerator = secrets.SystemRandom()
# returns current date and time
x = str(time.time()) + "-"
x += str(secretsGenerator.randint(0, 9999999999))
client_dynamo=boto3.resource('dynamodb')
# table name
table=client_dynamo.Table('Touchless-CU')
# try to send data
dictA = json.loads(event['body'])
# dictA = json.loads(json.dumps(event))
# parse custom json
dictB = {}
dictB['data_id'] = str(x)
dictC = {}
dictC['date'] = str(datetime.datetime.utcnow())
dictA.update(dictB)
dictA.update(dictC)
# merged_json = json.dumps(dictA)
# try and put in table
try:
response=table.put_item(Item=dictA)
return ("Done")
except:
# raise exception (remeber to send primary key)
raise