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

Sat, Jul 18, 2020

Read in 3 minutes

Introduction :

In this article we will see how to write a simple lamda function and test that and also how to solve the error which occurs when you start learning lamda.

Steps :

1. Create a maven project in eclipse 
2. Add the dependencies 
3. Write the code for lamda function 
4. Upload the lamda code into AWS
5. Test the lamda function

Create a maven Project in eclipse : File -> new maven project



If you opened the project structure ,you can find ,pom.xml and files .

Add the dependencies :

In the POM.xml add the below dependies

<!-- -->

<!-- -->

Write the code for lamda function

When you trying to write a lamda function in a class that class needs to implements the interface RequestHandler<> and always you have to pass object as a input (RequestHandler<Object, Object>) .

For example if you try to pass <String ,object > you will get the error “AWS Can not deserialize instance of java.lang.String out of START_OBJECT”.

And the interface RequestHandler is having a method ,

public O handleRequest(I input, Context context);

Inside this method you can write your logic for your lamda function .

Here ,I am planning to generate a random number and I getting input object and I am just printing that object.I am returning the random number generated as object by using

package com.theprogrammerguide.lamdademo;


public class App implements RequestHandler<Object, Object> {
public Object handleRequest(Object obj, Context context) {
Double temp = Math.random() * 100;

String random = Double.toString(temp);

System.out.println("input object received is" + obj.toString());
System.out.println("generated random number is" + random);
Input input =new Input();

return input;


Right click the project and select maven clean ,maven install and generate resources .Now the jar file might have been created in the “target " have to upload the jar into AWS lamda.

Upload the code ( or jar) into AWS

Login your AWS account .If you don’t have one ,get the introduction about AWS and you can login for the free tier account.

After login click services and select lamda and click on "create function" .


In the create function screen enter function name ,select java runtime what you are using in your eclipse .I am using java 8 so ,I selected that.



After click on “Create function " you might have landed into designer page.

In the function code section ,upload your jar and in the basic settings section ,you have to update the packagename.ClassName:: methodName.


And leave all other settings with the default entries .

Now your lamda function is ready to test.

Test the Lamda function :

To test the lamda function you have to configure the event. Click on test and As I am not using the input for my logic ,I just take the default input event.


Finally , you will geth the below screen of exceution result.