Reputation: 2208
I created a aws Lambda function which prints hello world to console
configured lambda with package name where the class is present and method name to call and uploaded jar file to aws lambda function.
when i execute lambda i get an exception saying class not found.
with message as
{
"errorMessage": "Class not found: com.coreservice.lambda.Handler",
"errorType": "class java.lang.ClassNotFoundException"
}
Can't able to understand why aws unable to find class inside jar.
Below Details are project configuration
public class Handler implements RequestHandler<SNSEvent, Object> {
@Override
public Object handleRequest(final SNSEvent input, final Context context) {
if (Objects.nonNull(input) && !CollectionUtils.isNullOrEmpty(input.getRecords())) {
context.getLogger().log("Hello World");
context.getLogger().log("queue = "+ SQS_URL);
}
return StringUtils.EMPTY;
}
}
project pom :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.coreservice</groupId>
<artifactId>SNS-SQS-Filter-Lambda</artifactId>
<packaging>jar</packaging>
<version>136.0.0-SNAPSHOT</version>
<name>SNS-SQS-Filter-Lambda</name>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.14</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source> <!-- or 1.8 -->
<target>1.8</target> <!-- or 1.8 -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Upvotes: 3
Views: 8344
Reputation: 2943
Change you lambda configuration for Handler from:
com.coreservice.lambda.Handler.handleRequest
to
com.coreservice.lambda.Handler
The com.coreservice.lambda.Handler class must implement the com.amazonaws.services.lambda.runtime.RequestHandler interface.
Upvotes: 6