Skip to content

Instantly share code, notes, and snippets.

@findtharun
Last active June 8, 2020 14:33
Show Gist options
  • Save findtharun/0d9d613a45b719cd9a8efd92baa7cc10 to your computer and use it in GitHub Desktop.
Save findtharun/0d9d613a45b719cd9a8efd92baa7cc10 to your computer and use it in GitHub Desktop.
import os
import io
import boto3
import json
import csv
# 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 = json.loads(json.dumps(event))
payload = data['data']
print(payload)
response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,
ContentType='text/csv',Body=payload)
result = json.loads(response['Body'].read().decode())
if(result=="0"):
result="Setosa"
elif(result=="1"):
result="Versicolor"
else:
result="Virginica"
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment