Search code examples
javaintellij-ideaaws-lambdaaws-sam-cliaws-toolkit

IntelliJ IDEA Config cant find AWS Lambda Handler in Default 'helloworld' Application


When setting the debug configurations for the default IntelliJ IDEA Java helloworld application (created upon making a new AWS Lambda project) the following response is shown:

Error: Cannot find handler 'helloworld.App::handleRequest' in project."

To fix this I've tried editing 'Handler' element inside template.yaml to include a filepath, though there had been no success.

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: HelloWorldFunction
      Handler: helloworld.App::handleRequest

I noticed the Python AWS Lambda helloworld project (within the PyCharm counterpart) required me to change the root project folder (allowing the handler to be found), however, I cant seem to achieve this with the Java counterpart within IntelliJ.

The default project file structure is as follows:

bash
├── README.mdH
├── HelloWorldFunction 
│   ├── pom.xml    
│   └── src
│       ├── main
│       │   └── java
│       │       └── helloworld
│       │           ├── App.java
│       │           └── GatewayResponse.java  
│       └── test  
│           └── java
│               └── helloworld
│                   └── AppTest.java
└── template.yaml

The relevant section of the template.yaml file contains:

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: HelloWorldFunction
      Handler: helloworld.App::handleRequest
      Runtime: java8
      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: get

The App.java file contains the class

public class App implements RequestHandler<Object, Object> {
    ...
}

I would like the debug configuration to point to the correct Handler ( being "helloworld.App::handleRequest") so I can run the project on my local machine.


Solution

  • On project files, right click on HelloWorldFunction then find Mark directory as and choose Source Root. That should fix your problems.

    enter image description here