Skip to content
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

Retrieve lambda event object on FastAPI #64

Closed
koxudaxi opened this issue Oct 27, 2019 · 6 comments
Closed

Retrieve lambda event object on FastAPI #64

koxudaxi opened this issue Oct 27, 2019 · 6 comments
Labels
improvement Improve an existing feature

Comments

@koxudaxi
Copy link
Collaborator

I use mangum with FastAPI.
Also, I often create an app which authenticates the request by Cognito

I want to obtain a few Cognito information(eg: cognitoIdentityPoolId ) from lambda event because I must use the information for business logic on API.
(https://docs.aws.amazon.com/lambda/latest/dg/with-on-demand-https.html)

Unfortunately, Mangum doesn't pass the raw lambda event object to a function(controller).
Is there a way to retrieve an event object of lambda?
Or, Could you please implement it?
Btw, I don't know how to pass it to a function 😕

@jordaneremieff
Copy link
Collaborator

I'm working on a PR that will include the event and context objects in the ASGI scope. I'll reference this issue when I push the changes.

@jordaneremieff
Copy link
Collaborator

@koxudaxi I've merged the changes into master. Here is an example of how you can access the event and context using FastAPI:

from fastapi import FastAPI
from starlette.requests import Request

app = FastAPI()


@app.get("/")
def hello_world(request: Request):
    return {"aws": request.scope["aws"]}

@koxudaxi
Copy link
Collaborator Author

Thank you very much!!

@erichaus
Copy link

erichaus commented Jan 4, 2020

greetings, just stumbled upon this, definitely would be helpful to have it in the main readme doc on the front page! went to access the apigateway event.requestContext.authorizor data and realized I didn't know how to get it :)

Thanks for the pr!

@jordaneremieff
Copy link
Collaborator

@erichonkanen yeah, there is definitely some work needed on the docs. There is an open issue for documentation generally #48.

I’ll try to get to it at some point, but open to PRs as well. :)

@iglikoxha
Copy link

It was changed to:
request.scope["aws.event"]

Still no documentation about it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improve an existing feature
Projects
None yet
Development

No branches or pull requests

4 participants