-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_inference.py
More file actions
35 lines (25 loc) · 1.1 KB
/
lambda_inference.py
File metadata and controls
35 lines (25 loc) · 1.1 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
import boto3
import json
import ast
def lambda_handler(event, context):
runtime_client = boto3.client('runtime.sagemaker')
endpoint_name = 'xgboost-2024-01-21-18-14-32-040'
sample = '{},{},{},{}'.format(ast.literal_eval(event['body'])['x1'],
ast.literal_eval(event['body'])['x2'],
ast.literal_eval(event['body'])['x3'],
ast.literal_eval(event['body'])['x4'])
response = runtime_client.invoke_endpoint(EndpointName=endpoint_name,
ContentType= 'text/csv',
Body=sample)
result = int(float(response['Body'].read().decode('ascii')))
if (result == 0):
result = 'Iris-setosa'
elif (result == 1):
result = 'Iris-versicolor'
elif (result == 2):
result = 'Iris-virginica'
print(result)
return {
'statusCode': 200,
'body': json.dumps({'prediction': result})
}