I keep getting this error message from my Lambda Function:
Tue Aug 18 21:15:31 UTC 2020 : Execution failed due to configuration error: Malformed Lambda proxy response
Tue Aug 18 21:15:31 UTC 2020 : Method completed with status: 502
What is I am trying to do is have a user enter two numbers. The lambda function takes those numbers and runs them through a function which references a list. The output is a row from the list containing two numbers, a name, and a default message. My Lambda function is in Python 3.6 and I am using API gateway using a GET method. List_r5 is a python script with a small list:
import json
from math import cos, asin, sqrt
import List_r5
print('Loading function')
#Parse out query string parameters
def lambda_handler(event, context):
usera_in = event['queryStringParameters']['usera_in']
userb_in = event['queryStringParameters']['userb_in']
print('UserA_In=' + usera_in)
print('UserB_In=' + userb_in)
#Define the function
def dis(us1, ub1, us2, ub2):
p = 0.017453292519943295
a = 0.5 - cos((us2-us1)*p)/2 + cos(us1*p)*cos(us2*p) * (1-cos((ub2-ub1)*p)) / 2
return 12742 * asin(sqrt(a))
def clo(database, input):
return min(database, key=lambda p: dis(v['us'],v['ub'],p['us'],p['ub']))
coord = {'us': usera_in, 'ub': userb_in}
output = clo(List_r5.data, coord)
sta_output = output['NAME']
us_output = output['us']
ub_output = output['ub']
#Body of response object
gResponse = {}
gResponse['Sta'] = sta_output
gResponse['UserA'] = us_output
gResponse['UserB'] = ub_output
gResponse['Message'] = 'All good on your end?'
#HTTP response object
responseObject = {}
responseObject['statusCode'] = 200
responseObject['headers'] = {}
responseObject['headers']['Content-Type'] = 'application/json'
responseObject['body'] = json.dumps(gResponse)
#Return response object
return responseObject
clofunction returnsmin(database...)immediately, meaning that the rest of the function, as well as the response object you actually want to return at the end of the function, becomes unreachable.clofunction?