I have made an API in AWS API Gateway which calls a Lambda function. This is the code which I have used to return the application/json response almost similar to a Python Lambda Blueprint:
def response(status_code, response_body=None):
return {
'statusCode': status_code,
'body': json.dumps(response_body) if response_body else json.dumps({}),
'headers': {
'Content-Type': 'application/json',
},
}
Currently I have only one HTTP Status code 200. I am having a hard time making the model schema for this response.
How do I get the body out of this response and properly display it to the consumer?
EDIT: I needed to create my API with Lambda Proxy Integration because here I am returning the response from Lambda and not transforming it at all. Also, there is no need for Models Schemas here. For more info, read the accepted answer.
Note: To avoid No 'Access-Control-Allow-Origin' header is present on the requested resource. error. Simply add 'Access-Control-Allow-Origin': '*' in the headers along with Content-Type
Cheers!