Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 946
David Avatar asked Apr 08 '19 15:04

David


People also ask

How do I run AWS Lambda in IntelliJ?

Refresh lists with AWS Lambda functions, JAR-artifacts, regions and profiles Select am AWS Lambda function in the list. Hit the button "Update Function". Type an input for test function of open it from json-file. Hit the Run button to run the test.

How do I provide AWS credentials in IntelliJ?

In IntelliJ IDEA, I'll click on the Save blue button. Then, in the AWS Explorer window, I'll click on the credentials drop-down menu. I can now see the Profile:default associated with my credentials. Once I select the default profile, IntelliJ IDEA will load a list of AWS services associated with my AWS account.

How do I create AWS Lambda project in IntelliJ?

Then, with IntelliJ IDEA, PyCharm, WebStorm, or JetBrains Rider already running, do one of the following: Open AWS Explorer, if it isn't already open. If you need to switch to a different AWS Region to create the function in, do that now. Then right-click Lambda, and choose Create new AWS Lambda.


1 Answers

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

like image 59
priiiiit Avatar answered Sep 18 '22 09:09

priiiiit