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.

Retrieve lambda event object on FastAPI

See original GitHub issue

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 😕

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
jordaneremieffcommented, Oct 27, 2019

@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"]}
0reactions
jordaneremieffcommented, Jan 4, 2020

@erichonkanen yeah, there is definitely some work needed on the docs. There is an open issue for documentation generally https://github.com/erm/mangum/issues/48.

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python FastAPI and AWS Lambda Container - Medium
To test the Lambda, you have to send to RIE a Lambda event. The event will be forwarded to the Lambda handler which...
Read more >
Observability Best Practices when running FastAPI in a Lambda
In this post, we will be looking at instrumenting logging, metrics, and tracing capabilities for a FastAPI application using AWS Lambda ...
Read more >
Simple Serverless FastAPI with AWS Lambda - deadbearcode
Click the Test button at the top of the dashboard and the select the Event Template dropdown and search for API Gateway Proxy....
Read more >
Migrating AWS Lamda + APIs to FastAPI + Mangum
My current Lambda function (main.py) is set up like this: # Lambda handler def handler(event, context): # if REST call if event. get('routeKey' ......
Read more >
Unable to determine handler from trigger event - AWS re:Post
To warm up Lambda function , I created a rule with schedule of 1 min with JSON text { "hello": "test"} with my...
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