How to debug quarkus lambda locally

1k views Asked by At

I am beginner to Quarkus lambda and when I am looking for how to debug the Quarkus lambda then everyone is showing with REST API endpoints, is there any way to debug the Quarkus app using lambda handler ?

I know how to start the app in dev mode but I am struggling with invoking the handler method.

3

There are 3 answers

1
Faisal Khan On

You can use SAM CLI for local debugging and testing. Here is the official documentation from quarkus.

It's really important that you follow the sequence.

Step-1:

sam local start-api --template target/sam.jvm.yaml -d 5005

Step-2:

Hit your API using your favourite rest client

Step-3

Add a Remote JVM debug configuration in your IDE, set your breakpoints and start debugging.

Remote JVM debugging

0
Alex On

You can actually just add a Main class and set up a usual Run Configuration.

 import io.quarkus.runtime.annotations.QuarkusMain;
 import io.quarkus.runtime.Quarkus;

 @QuarkusMain
 public class Main {
   public static void main(String ... args) {
       System.out.println("Running main method");
       Quarkus.run(args);
    }
 }

After that, just use curl or Postman to invoke the endpoint. By default, the lambda handler starts on port 8080. You can override it by passing

-Dquarkus.lambda.mock-event-server.dev-port=9999

So the curl will look like:

curl -XGET "localhost:9999/hello"

if the definition of the resource class looks like:

    @Path("/hello")
    public class GreetingResource {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
      public String hello() {
        return "hello jaxrs";
      }
    }

Add a breakpoint in the Resource class and start the Main class in Debug mode. This will actually pause during a debug on a breakpoint.

0
appel500 On

You can just run mvn quarkus:dev and connect a remote debugger to it on port 5005 as shown in this image

enter image description here

Once quarkus is started in dev mode and you connect the remote debugger you can use Postman to send a request. Your breakpoints will be evaluated.