-
-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation #48
Comments
Hi, I stumbled upon your library because I wanted to deploy a fastapi application to AWS Gateway and Lambda.
from fastapi import FastAPI
from mangum import Mangum
app = FastAPI()
@app.get("/ping")
async def pong():
"""
Sanity check.
This will let the user know that the service is operational.
And this path operation will:
* show a lifesign
"""
return {"ping": "pong!"}
handler = Mangum(app) Throws It runs perfectly fine as it should in its deployment destination API Gateway / Lambda, yet not in local development. Setting |
@iwpnd Lifespan refers to an ASGI sub-specification, you can read about it here: https://asgi.readthedocs.io/en/latest/specs/lifespan.html. It isn’t related to AWS behaviour (side note: I should probably document this here specifically since this may be a source of continual confusion). As to your specific issue, I haven’t attempted to reproduce it, but it looks like a conflict between Uvicorn and Mangum both trying to run the main async entry point. If you’re running the application with Uvicorn locally, then it probably isn’t necessary to wrap it with Mangum. You can run the app directly with an ASGI server unless you’re using something like serverless-offline or another local AWS Lambda/API Gateway emulator. |
Thank you @ERM, that's the confirmation I was hoping for.
It is not necessary, you're correct. I was hoping there was a more elegant way than commenting out the handler for local development. I will read up on the lifespan sub-spec for ASGI as you proposed. It's probably just something I need to wrap my head around. |
hi @ERM! I finished a little tutorial on how to deploy a fastapi with AWS Lambda/Gateway using Mangum. I mean it's not much, but I hope it helps some people to get started. Do you think I got the part about Mangum correct? If this is still on your agenda, I would be happy to help with Mangum documentation or examples to get me started with contributions on Github. |
@iwpnd had a read of your tutorial, good work! :) Yeah, documentation is still on the agenda, though I'm not quite sure how it should look. Mangum itself doesn't do a whole lot that needs to be specifically documented (could be wrong). I think the most useful additions would be code examples/deployment configurations, but those vary quite a bit so I'm not sure how to best include them here. Haven't had a lot of time to think about it lately, but I'm happy to review any PRs that could improve the docs - maybe something describing the lifespan behaviour would be a good start? |
What I've done is the following , i have a from mangum import Mangum
from app import main
assert main.app is not None
handler = Mangum(main.app) so that my main.py is what is launched by uvicorn (which therefore does not see the lambda_main.py code) |
@iwpnd you tutorial was useful to me at least ! I'm deploying using terraform and gitlab-ci but it was of good help the thing that your tutorial helped me clarify, and without I would have dismissed mangum, was the fact the |
@iwpnd I've been revamping the documentation since I've had a bit more time as of late. If you'd still like to contribute, maybe you could start with a section that links to examples/guides. I don't know how it should look, but feel free to come up with a structure and add a link to your post and I'll review. I'm tracking this here #104. |
No description provided.
The text was updated successfully, but these errors were encountered: