forked from servian/aws-step-function-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda-write-db.py
37 lines (32 loc) · 1.18 KB
/
lambda-write-db.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
import boto3
def lambda_handler(event, context):
'''
Adds the review data to the review database table
'''
#select correct table based on input data
dynamodb = boto3.client('dynamodb')
if event['reviewType'] == 'Product':
tableName = 'my-products-table'
elif event['reviewType'] == 'Service':
tableName = 'my-services-table'
else:
raise Exception("Input review is neither Product nor Service")
#construct response to put data in table
response = dynamodb.put_item(
TableName=tableName,
Item={
'reviewID': {"N": event['reviewID'] },
'customerID': {"N": event['customerID'] },
'productID': {"N": event['productID'] },
'feedback': {"S": event['feedback'] },
'sentiment': {"S": event['sentiment'] }
},
)
#pass through values
response['reviewType'] = event['reviewType']
response['reviewID'] = event['reviewID']
response['customerID'] = event['customerID']
response['productID'] = event['productID']
response['feedback'] = event['feedback']
response['sentiment'] = event['sentiment']
return response