Skip to content

Instantly share code, notes, and snippets.

@manmohanmirkar123
Last active December 30, 2023 11:20
Show Gist options
  • Save manmohanmirkar123/47cdf1d4682411ea8ec8a73ad79747e6 to your computer and use it in GitHub Desktop.
Save manmohanmirkar123/47cdf1d4682411ea8ec8a73ad79747e6 to your computer and use it in GitHub Desktop.

Today I tested the FASTAPI(python) lib with AWS Lambda URL . It worked as expected. Folowing is the code I used for it.

main.py

from fastapi import FastAPI
from mangum import Mangum

app = FastAPI()
handler = Mangum(app)

@app.get("/")
def baseurl():
    return {"Hello from Base PATH"}
@app.get("/hello")
def baseurl():
    return {"Hello from /hello PATH"}
@app.get('/user/{name}')
def show(name: str):
    return {f"Hello from the /user PATH {name}"}

In the code you can see that the handler is wrapped around the Magnum (Line#9)to worked well with AWS lambda. After deploying I tested the functioanlity using Lambda URL which worked as expected hence we dont need the API gateway config anymore.

Testing Results:

Test#1 PATH= / Image 30-12-23 at 4 20 PM

Test#2 PATH= /hello

image

Test #3 PATH= /user/

image

Even the swagger URL also opened correctly:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment