Last active
August 26, 2020 00:52
-
-
Save maxbrenner-ai/06c017cc60d6423d8fb8761327ae901f to your computer and use it in GitHub Desktop.
lambda function code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import io | |
import boto3 | |
import json | |
import csv | |
# grab environment variables | |
ENDPOINT_NAME = os.environ['ENDPOINT_NAME'] | |
# grab runtime client | |
runtime = boto3.client('runtime.sagemaker') | |
def lambda_handler(event, context): | |
# Load data from POST request | |
data = json.loads(json.dumps(event)) | |
# Grab the payload | |
payload = data['body'] | |
# Invoke the model. In this case the data type is a JSON but can be other things such as a CSV | |
response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME, | |
ContentType='application/json', | |
Body=payload) | |
# Get the body of the response from the model | |
result = response['Body'].read().decode() | |
# Return it along with the status code of 200 meaning this was succesful | |
return { | |
'statusCode': 200, | |
'body': result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment