-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLambdaFunction
35 lines (26 loc) · 934 Bytes
/
LambdaFunction
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
import json
import os
import boto3
import io
import csv
import numpy as np
#get environment variables
endpoint_name = os.environ['ENDPOINT_NAME']
runtime = boto3.client('runtime.sagemaker')
def lambda_handler(event, context):
# TODO implement
print("Received event :" + json.dumps(event, indent = 2))
data = json.loads(json.dumps(event))
payload = data['data']
print(payload)
response = runtime.invoke_endpoint(EndpointName = endpoint_name,
ContentType = 'text/csv',
Body = payload)
print(response)
result = json.loads(response['Body'].read().decode())
print(result)
#result = result.decode("utf-8")
#result = result.split(',')
pred = round(np.expm1(result))
#pred = int(result['predictions'][0]['prediction_label'])
return pred