aws / aws-toolkit-jetbrains

AWS Toolkit for JetBrains - a plugin for interacting with AWS from JetBrains IDEs
https://plugins.jetbrains.com/plugin/11349-aws-toolkit
Apache License 2.0
730 stars 198 forks source link

Cannot find handler in Classpath/handler not under direct source #2168

Open tchlyah opened 3 years ago

tchlyah commented 3 years ago

Describe the bug When trying to run or debug a Quarkus Amazon Lambda, either by using QuarkusStreamHandler, or from the produced template file sam.jvm.yaml, it refuses to run cause of the Error: Cannot find handler 'io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest' in project.

To reproduce

  1. Use example here: aws-quarkus-demo/lambda
  2. Add run configuration (AWS Lambda -> Local)
  3. Either set From template referencing the file target/sam.jvm.yaml, or set the Handler to io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest. => Error: Cannot find handler 'io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest' in project.

Running the default handler com.amazon.example.ProcessingLambda won't work because it doesn't support Quarkus CDI, as stated in https://quarkus.io/guides/amazon-lambda#create-the-function:

Do not change the handler switch. This must be hardcoded to io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest. This handler bootstraps Quarkus and wraps your actual handler so that injection can be performed.

Expected behavior Since the QuarkusStreamHandler is in the classpath, it should accept it and run the function.

Screenshots

Capture d’écran 2020-10-23 à 11 06 06

Your Environment

Additional context sam.jvm.yaml:

  AWSTemplateFormatVersion: '2010-09-09'
  Transform: AWS::Serverless-2016-10-31
  Description: AWS Serverless Quarkus - 1.0.0-SNAPSHOT
  Globals:
    Api:
      EndpointConfiguration: REGIONAL
      BinaryMediaTypes:
        - "*/*"

  Resources:
    MeasurementsFeeder:
      Type: AWS::Serverless::Function
      Properties:
        Handler: io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest
        Runtime: java11
        CodeUri: function.zip
        MemorySize: 256
        Timeout: 15
        Policies: AWSLambdaBasicExecutionRole
abrooksv commented 3 years ago

1.22 removed the handler validation when using a template so you can use that route as a workaround. We can't remove it from the non-template yet due to we do the validation to find the base directory to use as the CodeUri for SAM build.

We have discussed exposing that as a field if we can't infer it from the provided handler.