-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4 - client-visualization-pipe-api.py
52 lines (40 loc) · 1.32 KB
/
4 - client-visualization-pipe-api.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
import json
import boto3
def lambda_handler(event, context):
print("MyEvent:")
print(event)
# mycontext = event.get("context")
# method = mycontext.get("http-method")
method = event['context']['http-method']
if method == "GET":
# todo write code...
dynamo_client = boto3.client('dynamodb')
im_invoiceID = event['params']['querystring']['InvoiceNo']
print(im_invoiceID)
response = dynamo_client.get_item(TableName='Invoices', Key={
'InvoiceNo': {'N': im_invoiceID}})
print(response['Item'])
#myreturn = "This is the return of the get"
return {
'statusCode': 200,
'body': json.dumps(response['Item'])
}
elif method == "POST":
# mystring = event['params']['querystring']['param1']
p_record = event['body-json']
recordstring = json.dumps(p_record)
client = boto3.client('kinesis')
response = client.put_record(
StreamName='APIData',
Data=recordstring,
PartitionKey='string'
)
return {
'statusCode': 200,
'body': json.dumps(p_record)
}
else:
return {
'statusCode': 501,
'body': json.dumps("Server Error")
}