I had read all the articles about AWS Lambda dealing with .jar file but unfortunately I did not find the answer. Currently I had my code using the command line down below to upload to S3 (since my .jar file is too big so I can’t directly upload from lambda console:
mvn clean package shade:shade -D maven.test.skip=true
Also I had open the access policy to S3fullAccess for my lambda function, and my handler is set to:
com.example.demo.controller.AlgoCalculationHandler::handleRequest
here is my code structure
I had been stuck for hours that I constantly got this error, I did not get more info by checking cloudwatch log:
{
"errorMessage": "Class not found: com.example.demo.controller.AlgoCalculationHandler",
"errorType": "java.lang.ClassNotFoundException"
}
START RequestId: f8b7a098-e038-489f-ad72-28f0ff9fe77d Version: $LATEST
Class not found: com.example.demo.controller.AlgoCalculationHandler: java.lang.ClassNotFoundException
java.lang.ClassNotFoundException: com.example.demo.controller.AlgoCalculationHandler
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
END RequestId: f8b7a098-e038-489f-ad72-28f0ff9fe77d
REPORT RequestId: f8b7a098-e038-489f-ad72-28f0ff9fe77d Duration: 3.87 ms Billed Duration: 4 ms Memory Size: 512 MB Max Memory Used: 90 MB
Before I can successfully use lambda since my .jar is relatively smaller, I always upload my .jar file directly from lambda page, this is my first time to upload .jar to S3, I am not sure if this is any connection between this practice?
Thanks in advance if there’s anyone can help!
Here is my pom.xml setting
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>