我创建了一个aws Lambda函数,它将hello world打印到控制台
使用包名称配置lambda,其中包含类,以及要调用的方法名称和上传的jar文件到aws lambda函数。
当我执行lambda时,我得到一个异常,说找不到类。
消息为
{
"errorMessage": "Class not found: com.coreservice.lambda.Handler",
"errorType": "class java.lang.ClassNotFoundException"
}
无法理解为什么aws无法在jar中找到类。
详细信息是项目配置
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;
}
}
项目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>
答案 0 :(得分:2)
从以下位置更改Handler的lambda配置:
com.coreservice.lambda.Handler.handleRequest
到
com.coreservice.lambda.Handler
com.coreservice.lambda.Handler类必须实现com.amazonaws.services.lambda.runtime.RequestHandler接口。