in pipeline/enrichment/fn-call-sagemaker/main.py [0:0]
def handler(event, context):
logger.debug("Received event %s", event)
if "Body" not in event:
raise MalformedRequest("Input must include 'Body' string or object")
if "EndpointName" not in event:
if DEFAULT_ENDPOINT_NAME:
event["EndpointName"] = DEFAULT_ENDPOINT_NAME
elif DEFAULT_ENDPOINT_NAME_PARAM:
event["EndpointName"] = ssm.get_parameter(Name=DEFAULT_ENDPOINT_NAME_PARAM,)[
"Parameter"
]["Value"]
else:
raise MalformedRequest(
"Input must include 'EndpointName' if neither DEFAULT_ENDPOINT_NAME nor "
"DEFAULT_ENDPOINT_NAME_PARAM environment variables are set"
)
# Convert body if JSON:
if not isinstance(event["Body"], str):
event["Body"] = json.dumps(event["Body"])
if "ContentType" not in event:
event["ContentType"] = "application/json"
if "Accept" not in event:
event["Accept"] = "application/json"
return json.loads(smruntime.invoke_endpoint(**event)["Body"].read())