AWS Can not deserialize instance of java.lang.String out of START_OBJECT

InputStream should be able to handle any input.

Reference: https://docs.aws.amazon.com/lambda/latest/dg/java-handler.html

InputStream – The event is any JSON type. The runtime passes a byte stream of the document to the handler without modification. You deserialize the input and write output to an output stream.

public class Handler implements RequestHandler<InputStream, String> {
@Override
    public String handleRequest(InputStream event, Context context) {

It worked for me in all the scenarios when I change the type of input argument from String to Object.

public class LambdaFunctionHandler implements RequestHandler<Object, String> {

  @Override
  public String handleRequest(Object input, Context context) {
    String data= input != null ? input.toString() : "{}";
    context.getLogger().log("Input: " + data);
    return "Test completed."+data;
  }
}

************************** Added on 12 March 2021 ***************************

After working on a couple of Lambda implementations, I realized that the input argument is nothing but a plain string representation of a JSON structure or a Map<String, Object> representation. For the map representation, Key is the name of the attribute, and the value is (1) a String if it is a primitive value or (2) a List if it has multiple values, is another Map<String, Object> or another JSON structure. You can recover the JSON representation with:

    if(input instanceof String)
    {
        String lambdaInputJsonStr = (String)input;
    }
    else if(input instanceof Map)
    {
        String lambdaInputJsonStr = gson.toJson((Map)input);
    }

I tried with Object as parameter type as well as Pojo class and it worked in certain scenarios but while making a request from browser with API gateway URL, it failed and gave exact above error. Spent at least 2-3 hours to figure out that correct Signature, which would work in most cases is below. However this is for hello world example, you would obviously customize your input as per your requirement.

public class LambdaFunctionHandler implements RequestHandler<***Map<String,Object>,***  Customer> { 
    @Override
    public Customer handleRequest(***Map<String,Object> input***, Context context) {

    }
}

This is an error message during Lambda deserialization.

Your API Gateway mapping template is sending a JSON object, but your handler is expecting a String. Either send a raw string from API Gateway, or update your handler to use a POJO corresponding to your template output.

i.e.

public class MyPojo {
   private String input;
   public String getInput() { return input; }
   public void setInput(String input) { this.input = input; }
}

See: http://docs.aws.amazon.com/lambda/latest/dg/java-programming-model-req-resp.html