Lambda / API Gateway Internal Server Error

While updating a Lambda function tied to API gateway, I started getting an error when I hit the raw API endpoint. Previously, the Lambda function was returning a string and I had just updated the function to return JSON instead.

When I then hit the endpoint for the updated Lambda, I started getting this error {“message”: “Internal server error”}. To spare the many wrong roads I went down, the solution was straight forward. My function had previously returned a string, but, now, returning json, I needed to include a proper response code and header for the response to be rendered from the endpoint.

So, what was essentially:

1
2
print("string")
return None

became, instead:

1
2
3
4
5
return {
'statusCode': 200,
'headers': {'Content-Type': 'application/json'},
'body': json.dumps(array)
}