I have a simple java lambda function which has the following code
public String handleRequest(Map<String, Object> input, Context context) {
Map<String, String> result = new HashMap<String, String>() {{
put("status", "success");
}};
String resultStr = new GsonBuilder().create().toJson(result, HashMap.class);
logger.info("ended function successfully " + resultStr);
return resultStr;
}
I can see in the cloudwatch the following lines
2020-07-10T17:52:26.198-07:00
START RequestId: 1b0ff049-3a61-4874-9172-9bee142dc076 Version: $LATEST
2020-07-10T17:52:26.203-07:00
2020-07-11 00:52:26 INFO KVSTriggerLamda:53 - ended function successfully {"result":"Success"}
2020-07-10T17:52:26.204-07:00
END RequestId: 1b0ff049-3a61-4874-9172-9bee142dc076
My Amazon connects call triggers this function and plays a simple prompt of "Success" or "Error" depending on the state. I always get "error"
What should the correct return value? I have followed aws documentation which specifies that I need to provide a simple flat JSON return value.
I finally got it working by just returning the Map itself.
Map<String, String> result = new HashMap<String, String>() {{
put("status", "success");
}};
return result;
Thanks to @tgdavies comments -
The output type can be an object or void. https://docs.aws.amazon.com/lambda/latest/dg/java-handler.html#java-handler-types