Skip to content

java.lang.ClassNotFoundException: my.service.StreamLambdaHandler when running Maven archetype project locally using aws-sam-cli #153

@sisiguo

Description

@sisiguo
  • Framework version: 1.1
  • Implementations: Spring Boot

Scenario

I'm trying to create a new serverless Spring Boot application using the provided Maven archetype and following the instructions here: https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot.

However, when I try running the newly created project locally through the aws-sam-cli sam local start-api -t sam.yaml command and then hit the /ping endpoint via http://127.0.0.1:3000/ping I get a ClassNotFoundException complaining about the StreamLambdaHandler class.

Some googling have checking the created .jar file to ensure it has all dependencies packaged with the requisite global read permissions as mentioned here https://docs.aws.amazon.com/lambda/latest/dg/deployment-package-v2.html.

Running a zipinfo on the jar created by the shade plugin shows all the dependencies (including the StreamLambdaHandler class that it is complaining about) but it didn't have the required global read permissions:
screen shot 2018-06-05 at 2 55 12 pm

Seeing that, I tried switching out the shade plugin with the maven-assembly-plugin in the pom.xml as follows:

<plugin>
	<artifactId>maven-assembly-plugin</artifactId>
	<executions>
                <execution>
		           <phase>package</phase>
		            <goals>
		                  <goal>single</goal>
		            </goals>
		  </execution>
          </executions>
	  <configuration>
	         <descriptorRefs>
		            <descriptorRef>jar-with-dependencies</descriptorRef>
	          </descriptorRefs>
	  </configuration>
</plugin>

That creates a jar bundled with all the dependencies with the requisite global read permissions:
screen shot 2018-06-05 at 2 43 58 pm

I then updated the sam.yaml file to point to the correct jar file and tried executing sam local start-api -t sam.yaml again but encountered the same ClassNotFoundException.

I have not changed any other file or configuration that the Maven archetype has set-up.

I am also encountering this same problem on a separate project that I have deployed to AWS Lambda via the aws cloudFormation commands.

Expected behavior

Newly created project using the provided Maven archetype should run OOTB without errors.

Actual behavior

Getting a ClassNotFoundException on the StreamLambdaHandler.

Steps to reproduce

  1. Create new serverless Spring Boot project via:
mvn archetype:generate -DgroupId=my.service -DartifactId=my-service -Dversion=1.0-SNAPSHOT \
       -DarchetypeGroupId=com.amazonaws.serverless.archetypes \
       -DarchetypeArtifactId=aws-serverless-springboot-archetype \
       -DarchetypeVersion=1.1
  1. Build project via:
    mvn clean install (from root project directory)

  2. Run locally via:
    sam local start-api -t sam.yaml (from root project directory)

  3. Attempt to hit /ping endpoint in browser via:
    http://127.0.0.1:3000/ping

Full log output

screen shot 2018-06-05 at 2 29 48 pm

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions