I just cloned the java sample project and built the shaded jar based on the instructions.
But when I tried to invoke the function with echo '{ "some": "input" }' | sam local invoke GetHelloWorld, I got this Error:
START RequestId: ef986fd1-e2b2-4028-aaf3-b46870fc646b Version: $LATEST
java.lang.ClassNotFoundException: com.aws.codestar.projecttemplates.handler.HelloWorldHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
I double checked the handler path and CodeUri, they both are correct.
Could anyone please tell me what is missing here?
Thanks!
I've also tried to invoke my existing lambda function in java locally using sam local, but I got the same error message saying the class is not found. but my function can be invoked successfully on aws.
@rickypotato I tried to execute the same steps but had no problems:
I have maven 3.5.0 and java 1.8.0_131 installed on my laptop.
@rickypotato I just had the same problem. I cleaned my temp folder and reinstalled docker to fix the problem.
I was having this problem with my Docker installation through Homebrew. I reinstalled with Docker for Mac and now it works.
@jyustman it works! thanks!
I encountered this error again and I think that the Docker container can't access the shared drive due to old credentials. After resetting the credentials in Settings > Shared Drives it works again. So this time I didn't have to reinstall Docker.
I got below error when I execute [Run AS] option and choose AWS Sam Local for the project in Eclipse.
Tools, OS and IDE are below.
os: OS X Yosemite 10.10.5
Eclipse: Oxygen.2 Release (4.7.2)
Virtualbox:5.2.0 r118431
Docker:Docker version 17.10.0-ce
(I downloaded this as Docker tool box)
Users directory is in the shared file list on Virtualbox and the jar is in the directory under Users.
I do not know why just mounting it on vm is not possible.
Could anyone please tell me what I should check for fixing it?
[AWS Toolkit] Running command: /Users/naokihiromoto/.nodebrew/node/v6.10.3/bin/sam local invoke GetHelloWorld --event /Users/naokihiromoto/git/codestar-sandbox/template.yml --profile admin-codestar --template /Users/naokihiromoto/git/codestar-sandbox/.serverless.template
2018/01/02 23:22:28 Successfully parsed /Users/naokihiromoto/git/codestar-sandbox/.serverless.template
2018/01/02 23:22:28 Connected to Docker 1.33
2018/01/02 23:22:28 Fetching lambci/lambda:java8 image for java8 runtime...
java8: Pulling from lambci/lambda
Digest: sha256:15508a5c85822a4ecd6affbfd4da078107d4fd2016fa95c2f570fa51d1f75c87
Status: Image is up to date for lambci/lambda:java8
2018/01/02 23:22:32 Invoking com.aws.codestar.projecttemplates.handler.HelloWorldHandler (java8)
2018/01/02 23:22:32 Decompressing /Users/naokihiromoto/git/codestar-sandbox/target/HelloWorld-1.0.jar
2018/01/02 23:22:32 Mounting /private/var/folders/xl/4r_m5sl54mq18xwv8k9vfnh00000gn/T/aws-sam-local-1514902952207727365 as /var/task:ro inside runtime container
[32mSTART RequestId: 93ff0e89-3dd7-48b7-9277-b51d0da59e7b Version: $LATEST[0m
[31mjava.lang.ClassNotFoundException: com.aws.codestar.projecttemplates.handler.HelloWorldHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
[0m
[32mEND RequestId: 93ff0e89-3dd7-48b7-9277-b51d0da59e7b[0m
[32mREPORT RequestId: 93ff0e89-3dd7-48b7-9277-b51d0da59e7b Duration: 3.46 ms Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 3 MB [0m[AWS Toolkit] SAM Local invocation done.
Getting same issues on a Windows 10 system under an Active Directory system (its a corp laptop). Created a local user with admin and tried again, same issue.
Docker:
Version 18.03.0-ce-win59 (16762)
Channel: stable
Ran into this while attempting to SAM local my first project. Not sure if this will help anyone, but from the other comments I haven't seen anything specifically looking at this. My sam.yaml configuration file was configured with:
Properties:
Runtime: java8
Handler: kjd.alexa.AlexaHandler
and looking at the logs I saw that docker was mapping:
/path/to/project
and which made sense as to why there was no Class found. In my run configuration I forced the CodeUri to the location:
target/alexa-handler-fat-jar.jar
and re-ran. After doing so, the JAR was correctly deflated and loaded. More information on overriding the serverless template within the run config.
https://docs.aws.amazon.com/toolkit-for-eclipse/v1/user-guide/tke-sam-local.html#sam-local-advanced-settings
Closing this because it is not a SAM CLI issue.
Most helpful comment
@jyustman it works! thanks!