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
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.
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.
... 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
Additional context
Using sample code from https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/springboot2/pet-store
/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 53272I suppose the same error would occur if this
saminvocation 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..
Most helpful comment
@oskarv Thanks for your advice. Basically, I run the lambda using
sam local start-api -t sam.yaml -d 5005now. Then using remote debug feature in IDEA to debug the lambda. In this way, I can debug the code using breakpoints.