Skip to content

Instantly share code, notes, and snippets.


muZk/ Secret

Last active January 23, 2023 18:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import json
import boto3
def add_quotes(s):
if isinstance(s, str) and ',' in s:
return '"{}"'.format(s)
return str(s)
def lambda_handler(event, context):
request_body = json.loads(event["body"])
row_json = {
"0": 4863,
"ID_CASO": 3181,
"CATEGORIA": request_body["CATEGORIA"],
"SEXO": request_body["SEXO"],
"EDAD": request_body["EDAD"],
"REGION": request_body["REGION"],
"COMUNA": request_body["COMUNA"],
"PREVISION": request_body["PREVISION"],
"FECHA_DIAGNOSTICO": "2017-11-08",
"CT": request_body["CT"],
"CN": request_body["CN"],
"CM": request_body["CM"],
"PT": request_body["PT"],
"PN": request_body["PN"],
"PM": request_body["PM"],
"FECHA_DEFUNCION": "2019-06-09",
"FECHA_INICIO_TTO": "2018-03-09"
row = list(map(add_quotes, row_json.values()))
client = boto3.client("sagemaker-runtime")
response = client.invoke_endpoint(
EndpointName = "AskChewy",
ContentType = "text/csv",
Accept = 'application/json',
body = response['Body'].read().decode()
response_body = json.loads(body)
return {
"statusCode": 200,
"body": json.dumps(response_body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment