Unable to determine handler from trigger event

0

I am deploying back end application using python and fastapi. The application works fine. To warm up Lambda function , I created a rule with schedule of 1 min with JSON text { "hello": "test"} with my Lambda function as target. My fastapi example is as like fastapi 0.71.0 mangum 0.12.3

from fastapi import FastAPI
from mangum import Mangum


app = FastAPI()
handler = Mangum(app)

@app.get("/ping")
def ping():
    return {'response': 'pong'}

Following error generates

[ERROR] TypeError: Unable to determine handler from trigger event
Traceback (most recent call last):
  File "/var/task/mangum/adapter.py", line 88, in __call__
    handler = AbstractHandler.from_trigger(
  File "/var/task/mangum/handlers/abstract_handler.py", line 115, in from_trigger
    raise TypeError("Unable to determine handler from trigger event")
[ERROR] TypeError: Unable to determine handler from trigger event Traceback (most recent call last):   File "/var/task/mangum/adapter.py", line 88, in __call__     handler = AbstractHandler.from_trigger(   File "/var/task/mangum/handlers/abstract_handler.py", line 115, in from_trigger     raise TypeError("Unable to determine handler from trigger event")
asked 2 years ago3603 views
2 Answers
1

By default, the Lambda engine calls your function and is looking for an entry point like:

def lambda_handler(event, context):
    # your code goes here

You can see this when you create a new Python function.

If you're concerned about keeping your function warm, Lambda provisioned concurrency is normally a better way to go.

profile pictureAWS
EXPERT
answered 2 years ago
  • I used this approach but got this error Execution failed due to configuration error: Malformed Lambda proxy response. My app works fine with mangum but problem on schedule event.

0

I recently faced a similar issue and the solution is provided at https://repost.aws/questions/QU0A9xe6i_T6CfOWLeiWm4XA/api-gateway-with-lambda-unable-to-import-module-server-no-module-named-server

An example of handler is located at https://github.com/fortejas/example-serverless-python-api/blob/main/lambda-api/server.py

handler = Mangum(app)

You would also need to install the required python dependencies

Sample commands

  curl -O https://bootstrap.pypa.io/get-pip.py
  sudo python3.7 get-pip.py 
  python -m pip --version 
  rm get-pip.py 
  pipenv
  cd lambda-api/
  virtualenv -p /usr/bin/python3.7 vpy37
  source vpy37/bin/activate
  pip3 install fastapi
  pip3 install boto3
  pip3 install Magnum
  pip3 install uvicorn
profile picture
Sri
answered 2 years ago
  • I have installed all dependencies but error continues

  • Would you be able to post your code to a git repo/pastebin and provide the steps on how to reproduce the issue?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions