-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_lookup.py
55 lines (40 loc) · 1.09 KB
/
lambda_lookup.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
import boto3
import json
# define the DynamoDB table that Lambda will connect to
client = boto3.client('dynamodb')
table_name = "RequestRecords"
def handler(event, context):
orig_body = json.loads(event['body'])
op = orig_body['operation']
print('operation requested: ' + op)
if op != 'read':
return {
'statusCode': 400,
'body': 'Invalid operation requested'
}
id = orig_body['id']
print('item id requested: ' + id)
data = client.query(
TableName=table_name,
KeyConditionExpression='#name = :value',
ExpressionAttributeValues={
':value': {'S': id}
},
ExpressionAttributeNames={
'#name': 'Id'
}
)
print(data['Items'])
lst = []
for i in data['Items']:
entry = json.loads(i['JSON']['S'])
lst.append(entry)
response_payload = json.dumps(lst)
response = {
'statusCode': 200,
'body': response_payload,
'headers': {
'Content-Type': 'application/json'
},
}
return response