-
-
Save muZk/3b4c2050203c79838972af3b67c9c12e to your computer and use it in GitHub Desktop.
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 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"], | |
"SUBCATEGORIA": request_body["SUBCATEGORIA"], | |
"SEXO": request_body["SEXO"], | |
"EDAD": request_body["EDAD"], | |
"REGION": request_body["REGION"], | |
"COMUNA": request_body["COMUNA"], | |
"CODIG_COMUNA": "", | |
"PREVISION": request_body["PREVISION"], | |
"CONVENIO_ONCOLOGICO": request_body["CONVENIO_ONCOLOGICO"], | |
"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"], | |
"ESTADIO": "I", | |
"EXTENSION_DIAGNOSTICO": "LOCAL", | |
"ESTADO_VITAL": "FALLECIDO", | |
"FECHA_DEFUNCION": "2019-06-09", | |
"TTO_FALP_SUBCATEGORIA": "CIRUGÍA", | |
"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=",".join(row) | |
) | |
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