triggermesh/knative-lambda-runtime

Check the response format

sebgoa opened this issue · 4 comments

It seems we are returning the entire reponse including the statusCode.

Following a sample demo in:
https://github.com/sebgoa/klr-demo

If we deploy the function with sls we get:

$ curl https://10sjc1yh84.execute-api.us-east-1.amazonaws.com/dev/ping
{"message": "Hello, the current time is 09:03:58.049756"}

Just get the body

but with KLR:

curl http://python-test.sebgoa.k.triggermesh.io
{"statusCode": 200, "body": "{\"message\": \"Hello, the current time is 09:16:44.925908\"}"}

looks like this response format ({"statusCode":int, "body":"string",etc}) is supposed to be handled in AWS API Gateway service which may work as AWS Lambda proxy. I can be wrong with a wording, full description is here

So, on the one hand, I'd not want to add more AWS-like integrations to our custom runtime to keep it simple and pass function responses "as is". But on the other hand, I see many lambda functions with this response format, so I think I can make our AWS runtime check if response comes in API Gateway format, parse it and pass formed HTTP response to user.

I wouldn't modify anything. Indeed this response format is due to AWS APi gateway, there are other examples (functions not exposed via API gateway) that don't have such a response because they are tied to other services.

So we should not change things. Instead find better examples:

see Alexa for example which has yet a different response format:
https://github.com/serverless/examples/blob/master/aws-python-alexa-skill/handler.py

I wish I could notice last comment before my commit. However, I reverted it but we'll have it in commits history, just in case :)

API gateway format conversion can be enabled by setting EVENT env variable value to API_GATEWAY. Implemented here