Что делать, если при использовании триггера APIG функция возвращается с кодом ошибки 500?
Проверьте, был ли ответ функции на вызов API Gateway заключен в структуру, содержащую body(String), statusCode(int), headers(Map) или isBase64Encoded(boolean).
Ниже приведен пример ответа, возвращенного функцией Node.js, использующая триггер APIG.
exports.handler = function (event, context, callback) {const response = {'statusCode': 200,'isBase64Encoded': false,'headers': {"Content-type": "application/json"},'body': 'Hello, FunctionGraph with APIG',}callback(null, response);}
Ниже приведен пример ответа, возвращенного функцией Java, использующая триггер APIG.
import java.util.Map;public HttpTriggerResponse index(String event, Context context){String body = "<html><title>FunctionStage</title>"+ "<h1>This is a simple APIG trigger test</h1><br>"+ "<h2>This is a simple APIG trigger test</h2><br>"+ "<h3>This is a simple APIG trigger test</h3>"+ "</html>";int code = 200;boolean isBase64 = false;Map<String, String> headers = new HashMap<String, String>();headers.put("Content-Type", "text/html; charset=utf-8");return new HttpTriggerResponse(body, headers, code, isBase64);}class HttpTriggerResponse {private String body;private Map<String, String> headers;private int statusCode;private boolean isBase64Encoded;public HttpTriggerResponse(String body, Map<String,String> headers, int statusCode, boolean isBase64Encoded){this.body = body;this.headers = headers;this.statusCode = statusCode;this.isBase64Encoded = isBase64Encoded;}}