IntelliJ + AWS Toolkit + Serverless App: "Must be able to locate the handler in the project in order to deploy to Lambda"

Viewed 4759

I have created a new Serverless project in IntelliJ using a HelloWorld style template app. This app I managed to build, deploy and run remotely in my AWS account. I even managed to integrate it with API gateway to make it accessible through the internet.

As the project is setup, it has 1 Lambda function called HelloWorldFunction. Its handler is called "helloworld.App::handleRequest" and I can see the configuration for this in the template.yaml file.

Now I want to create another Lambda function in the same application project. So, in IntelliJ, I follow these steps:

  • AWS Explorer > Lambda
  • Right-click on Lambda
  • Click "Create new AWS Lambda ..."
  • enter a function name (e.g. MyNewLambdaFunction)
  • enter the runtime (Java 8) and the S3 bucket and the IAM role (all is fine)
  • then I need to enter the name of the "Handler", and this is where my problem starts

I have tried different names here, such as "MyNewHandler", or "helloworld.App::handleRequest" (clearly this wouldn't work because it's already in use by the HelloWorldFunction), "helloworld.App2::handleRequest", .... and so on.

Each time I try another name or way to define the Handler, I get this error message:

Must be able to locate the handler in the project in order to deploy to Lambda

Question:

Do I need to first configure the new Lambda function in the template.yaml file or what do I need to call the Handler so it will work?

I am sure this is just a noob-error but I have been Googling this and haven't found anyone who has run into the same problem. I also read up on AWS on handlers but it only describes it at a conceptual level and not in practice where there are multiple Lambdas.

thanks for any help!

Andy

4 Answers

I've had the same issues using pyCharm for Python.

I was able to solve it by using <file name without extension>.<function name> so my file is app.py and the function is lambda_handler so my handler was app.hello_world

It should be noted this is the same as what you see in the "Handler" field when using the AWS web management page.

My understanding is that you would need to add app2 class to the same package first:

click on the package name → new → Java Class → type app2

enter image description here

enter image description here

Navigate to the implementation of the App2 class and click on the lambda icon in the gutter. You will notice that "Create New AWS Lambda" is added to the dropdown:

enter image description here

When you select it, you will see that "Handler:" field has already been prepopulated correctly:

enter image description here

my understanding is that each handler must be placed in a separate class and the name of the handler handleRequest is standard and provided by the framework

Thius is how it looks in pycharm:

handler name in pycharm

I got the same issue but solved in a different way;

  • Quit WebStorm
  • Delete ".aws-sam" and ".idea" folders
  • Open the project again.

"Update function code" run without "Must be able to locate the handler in the project in order to deploy to Lambda"

Related