Code example: Copy the snippet and implement yourself
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class ClassName implements RequestStreamHandler {
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream,
Context context) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
JSONObject response = new JSONObject();
JSONParser parser = new JSONParser();
try {
JSONObject event = (JSONObject) parser.parse(reader);
//your code here. Use the jsonObject as you wish
response.put("isBase64Encoded", false);
response.put("statusCode", 200);
response.put("headers", headerJson);
response.put("body", "");
} catch (Exception ex) {
ex.printStackTrace();
response.put("statusCode", int);
response.put("exception", ex);
}
OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
writer.write(response.toString());
writer.close();
}
}
For response object JSON FOrmat follow link: https://aws.amazon.com/premiumsupport/knowledge-center/malformed-502-api-gateway/