-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1 - write-to-kinesis-lambda-code.py
More file actions
52 lines (40 loc) · 1.33 KB
/
1 - write-to-kinesis-lambda-code.py
File metadata and controls
52 lines (40 loc) · 1.33 KB
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_customerID = event['params']['querystring']['CustomerID']
print(im_customerID)
response = dynamo_client.get_item(TableName='Customers', Key={
'CustomerID': {'N': im_customerID}})
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")
}