Search code examples
amazon-web-servicesaws-lambda

How to create a custom runtime lambda function to stream response in Python


I am trying to implement a custom runtime for python lambda function because I want to implement streaming response, for which I have to make changes in the bootstrap file. I came across of two ways while exploring documentation:

  1. aws documentation to build custom runtime : it provides the example for lambda function written in bash and not Python. I am not sure what additionaly I should do make the lambda function python.

  2. deploying lambda function as a container: here it does not make use of bootstrap file, on which changes are to be made so that lambda function streams the response. I dont know how to set the bootstrap as the entrypoint here.

I would appreciate if I could receive suggestions/resources on which way is the right way and what exactly to do additionally to implement the custom runtime with bootstrap file and lambda functions.


Solution

  • So while researching I came across an alternative to stream responses in python lambda functions. It is to use AWS lambda web adapter. It uses the Custom Runtime API to implement response streaming behind the scenes.

    It supports multiple frameworks for which they have provided several examples in their github repository

    For response streaming in Python, FastAPI-response-streaming-zip example from their repository worked for me.