1

I am using Spring cloud function version 3.2.6. I have uploaded the zip file of jar in S3 bucket and then tried to upload to AWS Lambda using S3 URI. After successfull update of jar I am getting below error.

{
  "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/

Below is my 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>

I am using latest version of spring cloud function and trying to run it in AWS lambda. Some how FunctionInvoker class is not present. Please do let me know what am I missing.

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110

3 Answers3

1

The issue is not related to packaging. It is a little weird as when zar are pushed to S3 and S3 reference is given to the lambda it does not invoke. But if you directly add the jar to lambda then it invokes and lambda runs like charm.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 26 '22 at 13:46
  • You are right. I faced the same problem today and after struggling for an hour, I landed here and when I uploaded the .zip directly, it worked as expected. – Arvind Kumar Avinash Jul 30 '23 at 19:27
0

Perhaps some problem with packaging. Please take one of the samples as your starting point - https://github.com/spring-cloud/spring-cloud-function/tree/3.2.x/spring-cloud-function-samples Also, please go thru this quick start - https://docs.spring.io/spring-cloud-function/docs/current/reference/html/aws.html#_getting_started

Oleg Zhurakousky
  • 5,820
  • 16
  • 17
  • Followed the same steps still got the same issue. Can you please elaborate what can be the issue with packaging – Chandan Mishra Sep 07 '22 at 14:34
  • I do not understand what problem you are having. The samples I have pointed you out are working as I use them every day. So something is on your end, so you can push your app to github somewhere and we can take a look. Otherwise I am not sure what to say. CNFE is one of the simplest to understand. . class is simply not there, so something with your packaging - since it can not locate `FunctionInvoker` – Oleg Zhurakousky Sep 08 '22 at 13:56
  • Issue is not related to packaging it is related to S3 – Chandan Mishra Sep 22 '22 at 09:52
0

The problem is the packaging with aws sam

sam build will produce: function-sample-aws-0.0.1-SNAPSHOT.jar

mvn package will produce: function-sample-aws-0.0.1-SNAPSHOT-aws.jar

the -aws version works fine if manually uploaded to s3 but that's not practical.

just encountered this myself, about to go search for a solution

brianbruff
  • 2,092
  • 2
  • 14
  • 14