0

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.

0xh3xa
  • 4,801
  • 2
  • 14
  • 28
footy
  • 5,803
  • 13
  • 48
  • 96
  • What's the error code? – Chris Gong Jul 11 '20 at 01:24
  • Where can I get that? It just goes to the "error" line in amazon connect @ChrisGong – footy Jul 11 '20 at 01:51
  • 1
    I've only used the streaming handler signature, but I think you should create a result POJO and return that, letting the Lambda runtime do the JSON conversion: "The output type can be an object or void. The runtime serializes return values into text. If the output is an object with fields, the runtime serializes it into a JSON document. If it's a type that wraps a primitive value, the runtime returns a text representation of that value." https://docs.aws.amazon.com/lambda/latest/dg/java-handler.html#java-handler-types – tgdavies Jul 11 '20 at 02:06

1 Answers1

0

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

footy
  • 5,803
  • 13
  • 48
  • 96