forked from awslabs/amazon-bedrock-agent-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_function.py
147 lines (129 loc) · 4.01 KB
/
lambda_function.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
import json
def get_named_parameter(event, name):
return next(item for item in event['parameters'] if item['name'] == name)['value']
def get_named_property(event, name):
return next(
item for item in
event['requestBody']['content']['application/json']['properties']
if item['name'] == name)['value']
def claim_detail(payload):
claim_id = payload['parameters'][0]['value']
if claim_id == 'claim-857':
return {
"response": {
"claimId": claim_id,
"createdDate": "21-Jul-2023",
"lastActivityDate": "25-Jul-2023",
"status": "Open",
"policyType": "Vehicle"
}
}
elif claim_id == 'claim-006':
return {
"response": {
"claimId": claim_id,
"createdDate": "20-May-2023",
"lastActivityDate": "23-Jul-2023",
"status": "Open",
"policyType": "Vehicle"
}
}
elif claim_id == 'claim-999':
return {
"response": {
"claimId": claim_id,
"createdDate": "10-Jan-2023",
"lastActivityDate": "31-Feb-2023",
"status": "Completed",
"policyType": "Disability"
}
}
else:
return {
"response": {
"claimId": claim_id,
"createdDate": "18-Apr-2023",
"lastActivityDate": "20-Apr-2023",
"status": "Open",
"policyType": "Vehicle"
}
}
def open_claims():
return {
"response": [
{
"claimId": "claim-006",
"policyHolderId": "A945684",
"claimStatus": "Open"
},
{
"claimId": "claim-857",
"policyHolderId": "A645987",
"claimStatus": "Open"
},
{
"claimId": "claim-334",
"policyHolderId": "A987654",
"claimStatus": "Open"
}
]
}
def outstanding_paperwork(parameters):
for parameter in parameters:
if parameter.get("value", None) == "claim-857":
return {
"response": {
"pendingDocuments": "DriverLicense, VehicleRegistration"
}
}
elif parameter.get("value", None) == "claim-006":
return {
"response": {
"pendingDocuments": "AccidentImages"
}
}
else:
return {
"response": {
"pendingDocuments": ""
}
}
def send_reminder(payload):
print(payload)
return {
"response": {
"sendReminderTrackingId": "50e8400-e29b-41d4-a716-446655440000",
"sendReminderStatus": "InProgress"
}
}
def lambda_handler(event, context):
action = event['actionGroup']
api_path = event['apiPath']
if api_path == '/open-items':
body = open_claims()
elif api_path == '/open-items/{claimId}/outstanding-paperwork':
parameters = event['parameters']
body = outstanding_paperwork(parameters)
elif api_path == '/open-items/{claimId}/detail':
body = claim_detail(event)
elif api_path == '/notify':
body = send_reminder(event)
else:
body = {"{}::{} is not a valid api, try another one.".format(action, api_path)}
response_body = {
'application/json': {
'body': str(body)
}
}
action_response = {
'actionGroup': event['actionGroup'],
'apiPath': event['apiPath'],
'httpMethod': event['httpMethod'],
'httpStatusCode': 200,
'responseBody': response_body
}
response = {'response': action_response}
return response