Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sisiguo opened this issue Jun 5, 2018 · 2 comments
Assignees
Milestone

Comments

@sisiguo
Copy link

sisiguo commented Jun 5, 2018

  • 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

@sapessi
Copy link
Collaborator

sapessi commented Jun 14, 2018

Hey @sisiguo, we really need the aws-sam-cli folks to fix this. However, I think we may switch to Maven's assembly plugin instead of Shade going forward to avoid this.

@sapessi sapessi self-assigned this Jun 14, 2018
@sapessi sapessi added this to the Release 1.2 milestone Jun 14, 2018
@sapessi
Copy link
Collaborator

sapessi commented Jun 19, 2018

Looks like this was fixed in the latest version of the SAM CLI. resolving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants