Aws-toolkit-jetbrains: java.lang.ClassNotFoundException when debug springboot2 in local

Created on 25 Nov 2019  路  5Comments  路  Source: aws/aws-toolkit-jetbrains

Describe the bug

I'm new in AWS lambda and download the sample from https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/springboot2/pet-store
I also install aws-toolkit-jetbrains in IntelliJ, AWS CLI, SAM CLI. When I try to debug from StreamLambdaHandler using the toolkit in IntelliJ, java.lang.ClassNotFoundException: com.amazonaws.serverless.sample.springboot2.StreamLambdaHandler will happen. However, the application can run without error after deploy to AWS lambda.

To reproduce




  1. git clone the sample project
  2. Open Java class StreamLambdaHandler and click the lambda icon to debug the code.
  3. Use default event template of 'API Gateway AWS Proxy' as input, others set as default.
  4. Error output in console as below,
    /usr/local/bin/sam local invoke --template /Users/ryan/Documents/WorkSpace/Java/aws/lambda/pet-store/src/main/.aws-sam/build/template.yaml --event "/private/var/folders/vf/msvny93n2990vpxj3gvw2lb00000gn/T/[Local] StreamLambdaHandler-event.json" --debug-port 53272
    Invoking com.amazonaws.serverless.sample.springboot2.StreamLambdaHandler (java8)
    2019-11-25 20:12:29 Found credentials in environment variables.

Fetching lambci/lambda:java8 Docker container image......
Mounting /Users/ryan/Documents/WorkSpace/Java/aws/lambda/pet-store/src/main/.aws-sam/build/Function as /var/task:ro,delegated inside runtime container
Connected to the target VM, address: 'localhost:53272', transport: 'socket'
START RequestId: 04e64b0e-d63e-1dda-7e9f-801bd72b2989 Version: $LATEST
java.lang.ClassNotFoundException: com.amazonaws.serverless.sample.springboot2.StreamLambdaHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
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)

Exception in thread "main" java.lang.Error: java.lang.RuntimeException: java.lang.RuntimeException: Unexpected status code from invocation/response: 299
at lambdainternal.AWSLambda.(AWSLambda.java:66)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:114)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Unexpected status code from invocation/response: 299
at lambdainternal.LambdaRuntime.reportDone(LambdaRuntime.java:219)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:318)
at lambdainternal.AWSLambda.(AWSLambda.java:64)
... 3 more
Caused by: java.lang.RuntimeException: Unexpected status code from invocation/response: 299
at lambdainternal.LambdaRuntime.reportDone(LambdaRuntime.java:216)
... 5 more
Disconnected from the target VM, address: 'localhost:53272', transport: 'socket'

Expected behavior

Debug the application with breakpoint

Screenshots

N/A

Your Environment

  • OS: Mac OS 10.15.1
  • JetBrains' Product: IntelliJ
  • JetBrains' Product Version: 2019.2.4
  • Toolkit Version: 1.7
  • SAM CLI Version: 0.31.1
  • JVM/Python Version: Java 1.8.0_221 / Python 3.7.5

Additional context

Using sample code from https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/springboot2/pet-store

bug

Most helpful comment

@oskarv Thanks for your advice. Basically, I run the lambda using sam local start-api -t sam.yaml -d 5005 now. Then using remote debug feature in IDEA to debug the lambda. In this way, I can debug the code using breakpoints.

All 5 comments

/usr/local/bin/sam local invoke --template /Users/ryan/Documents/WorkSpace/Java/aws/lambda/pet-store/src/main/.aws-sam/build/template.yaml --event "/private/var/folders/vf/msvny93n2990vpxj3gvw2lb00000gn/T/[Local] StreamLambdaHandler-event.json" --debug-port 53272

I suppose the same error would occur if this sam invocation was done outside of the IDE. In that case this may be worth reporting to https://github.com/awslabs/aws-sam-cli/

/usr/local/bin/sam local invoke --template /Users/ryan/Documents/WorkSpace/Java/aws/lambda/pet-store/src/main/.aws-sam/build/template.yaml --event "/private/var/folders/vf/msvny93n2990vpxj3gvw2lb00000gn/T/[Local] StreamLambdaHandler-event.json" --debug-port 53272

I suppose the same error would occur if this sam invocation was done outside of the IDE. In that case this may be worth reporting to https://github.com/awslabs/aws-sam-cli/

I will try to rasie one to the aws-sam-cli as well. By the way, is there anything perticular to set up using aws-toolkit to run lambda base on springboot ?

This issue is rather old, so you probably figured it out. But, i was getting this error intermittently when i started using the toolkit, the problem for me was quite simple. Running lambda from Java class using "Lambda icon" didn't always pickup SAM template so even though it says that build is successful it was really not. What i found the safest way to run lambda using GUI ( naturally the best way is always the console ), is to run the lambda from the template it self. The template file will have an "standard green arrow icon" next to entry that represents your lambda function resource, try running it from there.

@oskarv Thanks for your advice. Basically, I run the lambda using sam local start-api -t sam.yaml -d 5005 now. Then using remote debug feature in IDEA to debug the lambda. In this way, I can debug the code using breakpoints.

Just one note regarding local debugging, once you've run sam local start-api -t sam.yaml -d 5005, invoke your lambda first and then attach your debugger..

Was this page helpful?
0 / 5 - 0 ratings