Error executing "Hello World" for AWS Lambda in Java

Read the error from the stack trace. It says "Can not deserialize instance of java.lang.String out of START_OBJECT token". The "START_OBJECT" token is '{'.

The problem was simply that you need to pass an actual String as input, e.g., "A String". This is your json input. Not {}. {} is not a String. You don't need any braces, just a string (in quotes). On the other hand, {} is a valid Person object, so it worked once you changed it to handle a Person as the input.


I tried with the following value in the test :

"TestInput"

instead of :

{ Input : "TestInput"}

and it seems to have worked fine.


For some reason Amazon can't deserialize json to a String. You would think String would be as general as input parameter as you can get but rightly or wrongly it's not compatible.

To handle JSON you can either use a Map or a custom POJO.

public class HelloWorldLambdaHandler {
    public String handleRequest(Map<String,Object> input, Context context) {
        System.out.println(input);
        return "Hello";
    }
}