10

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

AHL
  • 738
  • 3
  • 11
  • 35

4 Answers4

4

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.

MikeSchem
  • 950
  • 2
  • 16
  • 29
  • 1
    Amazing... there are two separate helper tooltips in the app and neither answer that basic question, thank you for this! – user7504939 Jun 29 '20 at 19:08
  • This answer could stand some fleshing out for the uninitiated, since python and PyCharm are of course different from Java and IntelliJ. I discovered that it's not even necessary to create a serverless project in PyCharm in order to create one or more Lambda functions that can be deployed in AWS but edited and tested locally in PyCharm. An application is often desirable anyway, but the functions created inside it wind up having weird names and sometimes an application isn't needed, just a function or 2. – hBrent Jun 30 '21 at 21:05
4

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

AstroSharp
  • 1,872
  • 2
  • 22
  • 31
  • thanks for the detailed guidance - I will give this a try. for now I have just packed all calls to my functions into that single handler, but still need to separate it – AHL Nov 28 '19 at 23:06
  • after a couple of days of playing with the project structure, I have developed a gut feeling that each lambda should be in a separate Java module since each lambda is independently compiled, packaged, sent to an S3 bucket, and deployed. If I keep multiple lambda handlers on the same class, then each lambda deploy will have compiled code for all other lambdas. It will slow down the deployemnt and use more space than needed in S3 – AstroSharp Dec 06 '19 at 19:04
1

Thius is how it looks in pycharm:

handler name in pycharm

AGR
  • 321
  • 6
  • 8
0

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"