forked from aws-samples/aws-nlp-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentercustomerfeedback.py
46 lines (46 loc) · 1.53 KB
/
entercustomerfeedback.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
import os
import json
import uuid
import boto3
from datetime import datetime
dynamodb = boto3.client('dynamodb')
def lambda_handler(event, context):
print('Received event: ' + json.dumps(event, indent=2))
table_name=os.environ['table_name']
firstname = event['FirstName']
lastname = event['LastName']
feedback = ''
if 'Feedback' in event:
feedback = event['Feedback']
data_event_isactive = 'no'
try:
if feedback == '':
response = dynamodb.update_item(
TableName=table_name,
Key={
'ID':{'S':str(uuid.uuid4())},
'PostedTime':{'S':datetime.now().isoformat()}
},
AttributeUpdates={
'FirstName':{'Value': {'S':firstname}},
'LastName':{'Value': {'S':lastname}}
}
)
else:
response = dynamodb.update_item(
TableName=table_name,
Key={
'ID':{'S':str(uuid.uuid4())},
'PostedTime':{'S':datetime.now().isoformat()}
},
AttributeUpdates={
'FirstName':{'Value': {'S':firstname}},
'LastName':{'Value': {'S':lastname}},
'Feedback':{'Value': {'S':feedback}}
}
)
print(response)
return response['ResponseMetadata']['HTTPStatusCode']
except Exception as e:
print('Actual error is: {0}'.format(e))
return e