-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
30 lines (22 loc) · 819 Bytes
/
Copy pathlambda_function.py
File metadata and controls
30 lines (22 loc) · 819 Bytes
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
import os
import io
import boto3
import json
import csv
import numpy as np
# grab environment variables
ENDPOINT_NAME = os.environ['ENDPOINT_NAME']
runtime= boto3.client('runtime.sagemaker')
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
data = event['body']
payload = {"instances" : [data]}
print(payload)
response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME, ContentType='application/json', Body=json.dumps(payload))
print(response)
output = json.loads(response['Body'].read().decode('utf-8'))
print(output)
label = np.argmax(output['predictions'])
final_output = 'The predicted number is {}'.format(label)
print(final_output)
return final_output