A Lambda triggered by an API has to return a dictionary with certain keys and values in order to not cause an error in execution (e.g. “malformed lambda proxy response”). These are the status code, body (JSONified), and if it’s base64 encoded. Headers can also be added to this structure, but they don’t seem required.

Code Example#

    return {  
      "statusCode": 200,  
   "body": json.dumps(f"User {username} not found"),  
   "isBase64Encoded": False  
  }

Sources#