Replies: 3 comments 2 replies
-
Please try using mangum 0.11 in your requirements. This fixed it for me. Not sure if it is an issue with AWS Lambda or mangum. |
Beta Was this translation helpful? Give feedback.
-
@VictorBac the problem appears to be that the local invocation does not include an event payload, so the Mangum handler is unable to identify the service invoking the function. Mangum uses the event data to determine which keys to map to the Not sure what service you are using for your deployed environment, but you'll need a payload format like the one displayed in the docs for API Gateway requests. |
Beta Was this translation helpful? Give feedback.
-
@AlphonsG your suggestion is correct! If anyone wants to write Python tests to hit your endpoints, try this:
from fastapi import FastAPI
from mangum import Mangum
app = FastAPI()
handler = Mangum(app)
@app.get("/")
async def root():
return {"message": "Hello World!"}
import json
import requests
def test_endpoint(endpoint: str):
url = 'http://localhost:9000/2015-03-31/functions/function/invocations'
response = requests.get(
url,
json={
"resource": endpoint,
"path": endpoint,
"httpMethod": "GET",
"requestContext": {},
"multiValueQueryStringParameters": None,
},
)
data = json.loads(response.json()['body'])
return data
if __name__ == "__main__":
response = test_endpoint("/")
assert response['message'] == "Hello World!" # passes |
Beta Was this translation helpful? Give feedback.
-
Hey guys,
I am trying to build d coker iamge to deploy on aws lambda following the doc and:
https://docs.aws.amazon.com/lambda/latest/dg/images-create.html#images-create-from-base
https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-base
My Dockerfile:
requirement.txt:
app.py:
then:
But when I try to query locally (following the doc):
I tried using (found in some discussions)
and even from another discussion:
it never works. (same error when deployed to aws lamda and not run locally)
I tried to use previous version but also had issue...
does anyone has a working example for this ?
Beta Was this translation helpful? Give feedback.
All reactions