I have a simple FastAPI REST server running on AWS Lambda. It is writing logs to S3 using Firehose.
Batching writes for low latency
To keep latency low, I am batching 20 events in each writes to Firehose, run in a FastAPI BackgroundTasks.
Blocking background task
Writes is done in a normal function, not in an async. I can see that it running in a separate thread from the main loop. However nothing is happening in the main loop while this write is going on.
Background task shutdown when AWS Lambda is inactive
I have also tried to have an async periodic background task running and to flush events that has not reached 20 running once a minute. However this background task shuts down unless there are constant traffic to the endpoint.
Set Uvicorn workers in AWS Lambda?
A possible problem is that Uvicorn is running with 1 worker. I have also tried find a place to change the number of Uvicorn workers in Terraform or AWS console, but I have not found a way to do this.
AWS Lambda FastAPI tech stack
My problem seems quite basic, and I cannot tell AWS Lambda FastAPI is a suitable tech stack for what I am doing?