jordaneremieff / mangum

AWS Lambda support for ASGI applications
https://mangum.io/
MIT License
1.67k stars 119 forks source link

RuntimeError: adapter was unable to infer a handler #265

Closed Fak3 closed 2 years ago

Fak3 commented 2 years ago

docker-compose.yml:

version: "3.4"
services:
  sust-fastapi:
    container_name: sust-fastapi
    tty: true
    build: &build
      context: .  
      dockerfile: ./Dockerfile-lambda
    volumes:
      - ~/.aws-lambda-rie:/aws-lambda
    entrypoint: "bash -c '/aws-lambda/aws-lambda-rie python -m awslambdaric src.itc_api.handler'"
    ports:
      - target: 8080  # aws-lambda-rie
        published: 8000

itc_api.py:


from fastapi import FastAPI, HTTPException, status
from mangum import Mangum

app = FastAPI()

@app.get("/objectEvents/")
async def get_objectEvents():
    return {}

handler = Mangum(app)  # AWS lambda hadler

When i start the docker-compose and then send POST request: curl -XPOST "http://localhost:8000/2015-03-31/functions/function/invocations" -d '{}'

i get an error: sust-fastapi | 28 Jun 2022 12:51:13,907 [INFO] (rapid) extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory sust-fastapi | 28 Jun 2022 12:51:13,907 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory sust-fastapi | START RequestId: 910cde42-d38c-46d0-a2f9-76afe136dc68 Version: $LATEST

sust-fastapi | [ERROR] RuntimeError: The adapter was unable to infer a handler to use for the event. This is likely related to how the Lam    raise RuntimeError( # pragma: no coverine 55, in inferl__the request payload is valid for a supported handler.) sust-fastapi | END RequestId: 910cde42-d38c-46d0-a2f9-76afe136dc68

jordaneremieff commented 2 years ago

This is expected.

The error you're encountering will occur when invocation payload does not contain the necessary information to handle the request. See https://github.com/jordaneremieff/mangum/discussions/218 and related discussions for more information.