question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support new API Gateway HTTP APIs

See original GitHub issue

Hi there, I’m getting the following error when my app executes in API Gateway (paths shortened for brevity):

Traceback (most recent call last):
  File "/virtualenv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 134, in handle
    self.handle_request(listener, req, client, addr)
  File "/virtualenv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 175, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/virtualenv/lib/python3.8/site-packages/mangum/adapter.py", line 61, in __call__
    raise exc
  File "/virtualenv/lib/python3.8/site-packages/mangum/adapter.py", line 59, in __call__
    response = self.handler(event, context)
  File "/virtualenv/lib/python3.8/site-packages/mangum/adapter.py", line 76, in handler
    response = self.handle_ws(event, context)
  File /virtualenv/lib/python3.8/site-packages/mangum/adapter.py", line 130, in handle_ws
    request_context = event["requestContext"]
KeyError: 'requestContext'

Here is my FastApi app code:

from fastapi import FastAPI

from app.api import router


def get_application(config) -> FastAPI:
    application = FastAPI(
        title=config.PROJECT_NAME, debug=config.DEBUG, version=config.VERSION
    )
    application.include_router(router, prefix=config.API_PREFIX)

    return application

And here is the Mangum adapter:

from mangum import Mangum

from .app import get_application
from .core import config

handler = Mangum(app=get_application(config), enable_lifespan=False)

Also tried running locally with gunicorn, same error. If I run the app normally with uvicorn it works fine.

I’m using the latest version of FastAPI (0.54.1) and Python 3.8 on a Manjaro Linux machine.

So, according to the examples I’ve read, that looks like pretty standard stuff; I looked online but couldn’t find anything (and the issues posted here seems like they are for old versions), am I missing something?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jordaneremieffcommented, Apr 18, 2020

Released in 0.8.0.

1reaction
jordaneremieffcommented, Apr 14, 2020

I’ve merged the PR for this into master, but there are a few things I want to do before the next release (probably this weekend). I’ll leave this open until then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with HTTP APIs - Amazon API Gateway
REST APIs and HTTP APIs are both RESTful API products. REST APIs support more features than HTTP APIs, while HTTP APIs are designed...
Read more >
The Official Guide to AWS HTTP APIs - Serverless Framework
AWS HTTP APIs are the latest iteration of tooling for creating APIs with the Amazon API Gateway. They offer a variety of significant...
Read more >
API Gateway REST vs. HTTP API: What Are The Differences?
AWS API Gateway is a great technology for managing and securing access to your backend REST APIs. However, AWS currently supports two very ......
Read more >
Amazon API Gateway for the .NET Developer - How To Build ...
Once you click 'Review and Create', a new API Gateway Endpoint is ... Supported Integration types when building HTTP APIs on Amazon API ......
Read more >
AWS API Gateway: HTTP vs REST
AWS API Gateway provides two different service, REST and HTTP and it can ... introduced a new flavor of the API Gateway, called...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found