-
Notifications
You must be signed in to change notification settings - Fork 2
/
handler.py
31 lines (26 loc) · 1.24 KB
/
handler.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
import json
import os
import boto3
from random import *
import sql
def handle_aurora_crud(event, context):
request_body = event['body']
event_type = request_body['eventType']
databaseName = os.environ['DatabaseName']
awsSecretStoreArn = os.environ['AwsSecretStoreArn']
dbClusterOrInstanceArn = os.environ['DbClusterArn']
if event_type == "createTable":
sql.create_table(databaseName, awsSecretStoreArn, dbClusterOrInstanceArn)
return {"success": True, "message": "Created Table"}
if event_type == "getRecords":
records = sql.get_records(databaseName, awsSecretStoreArn, dbClusterOrInstanceArn)
return {"success": True, "records": records}
if event_type == "saveRecord":
record_info = request_body['recordInfo']
record_info['record_id'] = randint(1,10000000)
sql.create_record(databaseName, awsSecretStoreArn, dbClusterOrInstanceArn, record_info)
return {"success": True, "message": "Saved Record", "record": record_info}
if event_type == "updateRecord":
record_info = request_body['recordInfo']
sql.update_record(databaseName, awsSecretStoreArn, dbClusterOrInstanceArn, record_info)
return {"success": True, "message": "Updated Record"}