我使用的是Springcloud函数版本3.2.6。我已经在S3 bucket中上传了jar的zip文件,然后尝试使用S3 URI上传到AWS Lambda。在成功更新jar之后,我得到了以下错误。
{
"errorMessage": "Class not found:
org.springframework.cloud.function.adapter.aws.FunctionInvoker",
"errorType": "java.lang.ClassNotFoundException"
}
START RequestId: 7b189d8c-c597-4335-b598-76b9b3a1f639 Version: $LATEST
Class not found: org.springframework.cloud.function.adapter.aws.FunctionInvoker:
java.lang.ClassNotFoundException
java.lang.ClassNotFoundException:
org.springframework.cloud.function.adapter.aws.FunctionInvoker. Current classpath:
file:/var/task/
下面是我的POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.acko</groupId>
<artifactId>phoenix</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>phoenix</name>
<description>phoenix</description>
<properties>
<java.version>14</java.version>
<wrapper.version>1.0.27.RELEASE</wrapper.version>
<aws-lambda-events.version>3.11.0</aws-lambda-events.version>
<spring-cloud-function.version>3.2.6</spring-cloud-function.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-aws</artifactId>
<version>3.2.6</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>${aws-lambda-events.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-dependencies</artifactId>
<version>${spring-cloud-function.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>${wrapper.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.1</version>
</dependency>
</dependencies>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>aws</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
<resource>META-INF/spring.factories</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>alpha</module>
</modules>
</project>
我正在使用最新版本的spring-cloud函数,并尝试在AWS lambda中运行它。一些函数调用程序类不存在的原因。请告诉我我缺少什么。
该问题与包装无关。这有点奇怪,因为当zar被推到S3时,S3引用被赋予了它不调用的lambda。但是,如果您直接将jar添加到lambda中,那么它就会调用并像魅力一样运行lambda。
也许是包装有问题。请以其中一个样品为出发点-https://github.com/spring-cloud/spring-cloud-function/tree/3.2.x/spring-cloud-function-samples此外,请快速启动-https://docs.spring.io/spring-cloud-function/docs/current/reference/html/aws.html#_getting_started
问题是使用aws-sam 的包装
sam构建将生成:function-sample-aws-0.0.1-SNAPSHOT.jar
mvn包将生成:function-sample-aws-0.0.1-SNAPSHOT-aws.jar
如果手动上传到s3,-aws版本可以正常工作,但这并不实用。
我自己刚刚遇到了这个,正要去寻找解决方案