How to call an existing lambda via fast api deployed to aws lambda?

317 views Asked by At

I'm following an example of how to create an fast api and use magnum adapter and deploy the application as an aws lambda. I understand all of the fast api is zipped up and executed as an lambda. we can define routes ( sample code below) . in the following set up, can we set up an route to call an existing lambda function? or in other words, create a route that calls another lambda function?

from fastapi import FastAPI
from mangum import Mangum

app = FastAPI()


@app.get("/")
def root():
    return {"message": "Up and running!"}


handler = Mangum(app)

1

There are 1 answers

0
pgrzesik On

Yes, it's possible to invoke separate function directly with boto3 for example: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda/client/invoke.html

Alternatively, if your other function is running behind an API Gateway, you can just hit the endpoint that calls that function.

Note: If you need to synchronously call other Lambda functions from your function, you might run into cascading cold-start issues. What functionality do you want to build?