Describe the bug
I cannot run my lambda function locally because the handler cannot be found.
To reproduce
Error: Cannot find handler 'app.lambda_handler' in project.Expected behavior
It should run the function specified in the lambda_handler variable, see second screenshot
Screenshots


Your Environment
Additional context
Can you show your project's folder structure in the Project window?
Can you show your project's folder structure in the Project window?
Of course, see here:

Is there a requirements.txt file somewhere?
Is there a requirements.txt file somewhere?
Yup, if you look in the screenshot above it's in the hello_world folder
I think the problem is that your local configuration's Handler isn't taking into account app.py is inside the project_directory/hello_world folder.
Essentially you're trying to run app.lambda_handler from the root project_directory rather than from inside hello_world.
Try changing it to hello_world/app.lambda_handler
It should be generating the code uri to be hello_world and handler is app.lambda_handle.
I thought I had a unit test for your setup. Will look into it.
I think the problem is that your local configuration's Handler isn't taking into account app.py is inside the project_directory/hello_world folder.
Essentially you're trying to run app.lambda_handler from the root project_directory rather than from inside hello_world.
Try changing it to hello_world/app.lambda_handler

I'm not sure that is the issue, since it worked once I defined lambda_handler as a function
The handler should be relative to the requirements.txt
I also catch this error. Seems like a bug when try to use sb.lambda_handler() as lambda handler. I wrapped handler and it works for me:
def handler(*args, **kwargs):
skill_handler = sb.lambda_handler()
return skill_handler(*args, **kwargs)
def handler(args, *kwargs):
skill_handler = sb.lambda_handler()
return skill_handler(args, *kwargs)
I can confirm that this works

Thanks a lot for the workaround!
We currently have the limitation that the handler has to be in your project's source.
I am trying to implement a custom resource for CFN and I am using this library https://github.com/ryansb/cfn-wrapper-python to wrap my create, update and delete handlers. The library expects you to set the handler like so:
import cfn_resource
# set `handler` as the entry point for Lambda
handler = cfn_resource.Resource()
@handler.create
def create_thing(event, context):
# do some stuff
return {"PhysicalResourceId": "arn:aws:fake:myID"}
@handler.update
def update_thing(event, context):
# do some stuff
return {"PhysicalResourceId": "arn:aws:fake:myID"}
The toolkit doesnt allow you to specify a handler this way.
In the process of trying to setup local debugging and seeing a similar error with nodejs
Error: Cannot find handler 'app.lambdaHandler' in project.
Initially I had used the following:
Runtime: nodejs12.x
Changed this to
Runtime: nodejs10.x
And it works fine now
SAM CLI, version 0.39.0
In the process of trying to setup local debugging and seeing a similar error with nodejs
Error: Cannot find handler 'app.lambdaHandler' in project.
Initially I had used the following:
Runtime: nodejs12.x
Changed this to
Runtime: nodejs10.x
And it works fine now
SAM CLI, version 0.39.0
Same issue, and changing runtime also fixes it.
Project structure is:
│ package.json
│ index.js
│
└───deploy
│ │ sam.yml
│
└───node_modules
│ ...
Node 12 support is done in master but not yet released.
It happened to me with my python3.7 project, turned out the python plugin for the community edition was blocking my Intellij Ultimate python plugin.
Solution:
Node 12 support is done in master but not yet released.
Is node12 support done? I'm seeing the same issue, but changing to node10 doesn't work.
@snowe2010 The problem for me ended up being the signature of the exports.handler function...
exports.handler = async (event, context, callback) => {
Doesn't work for me however when I change it to
exports.handler = async (event, context) => {
or
exports.handler = async event => {
I am able to run the function. I also have not marked any directories and in my template.yaml I have
Resources:
ImageProcessFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: image-process
Handler: app.handler
the function file relative to the project root is image-process/app.js
Hope this helps :)
I run into this too with python3.7 runtime! When specify lambda handler as a an object (lets call it obj) with implemented def __call__(event, context) I can't get valid run configuration.
Yet everything works if I just wrap that object into:
def lambda_handler(event, context):
return obj(event, context)
Had this problem with the Hello world example on the python 3.8 runtime as well....
No changes to the generated source, it just can't find the handler...
Same for me very very frustrating... try every thing/path..
Also there is a in the configuration, if you have an error, even though you correct it, the create fuction still disabled
Regards
We current require being able to locate the Lambda handler in checked out source. This is a heuristic based system and does not cover all use cases.
We are slowly moving away from this hard requirement.
For run configurations using a template file, we no longer have this requirement.
For run configurations that specify a handler, this is still in place since we have not exposed a way for users to set the base directory we use to kick off a SAM build for.
I have folder/src/lambda_function.pyhttp://function.py
And the the lambda handler
What should I write in the config I have tried absolute/relative path...
Nothing work
Regards
Steph
Le 19 févr. 2021, à 4 h 41 p.m., Austin Brooks <[email protected]notifications@github.com> a écrit:
We current require being able to locate the Lambda handler in checked out source. This is a heuristic based system and does not cover all use cases.
We are slowly moving away from this hard requirement.
For run configurations using a template file, we no longer have this requirement.
For run configurations that specify a handler, this is still in place since we have not exposed a way for users to set the base directory we use to kick off a SAM build for.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Faws%2Faws-toolkit-jetbrains%2Fissues%2F1201%23issuecomment-782375616&data=04%7C01%7C%7C943d430b702842717e9f08d8d51f1fe9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637493676938248015%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=lSjEGj2Idfh%2BUNeJ5p6y66FmBFOXrzCcIUUh9xT1ruw%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGF2DBWACTNHB4CNMLV74NTS73LIZANCNFSM4IUQ6KNQ&data=04%7C01%7C%7C943d430b702842717e9f08d8d51f1fe9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637493676938257972%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=5FQBwr4CxdEFddGEE%2BuU%2F22%2FQBjr4Mfmp03kkPgfsZ0%3D&reserved=0.
Most helpful comment
Node 12 support is done in master but not yet released.