I will be using the async python web framework AIOHTTP. In case that you may not have heard or used it before I would advice you to jump quickly to the official documentation here and briefly skim through the introduction.

All the code used in this tutorial is also on github.


Lets start off with the HTTP server! I am going to use python@3.7 and pipenv as my package manager and virtual environment but feel free to use any other tool that you might be familiar with. Run the following to start a new python3 environment:

pipenv --python 3.7

Before writing any code, we need to first install our dependencies. For the time being, aiohttp will suffice to get the HTTP server up and running. so lets install it:

pipenv install aiohttp

Now we can start off with our Application class.

## application.py

from aiohttp import web

class Application(web.Application):
    def __init__(self):
    def run(self):
        return web.run_app(self, port=8000)
application = Application()
if __name__ == '__main__':

On a quick note, you have to call the new application instance ‘application’ since elastic beanstalk expects that variable name by default when booting the app, direct quote of the docstring from on the official doc:

“EB looks for an ‘application’ callable by default.”

At this point you have a fully runnable web server:

python application.py

======== Running on ========

#elastic-beanstalk #aws #python #aiohttp #grpc

Running an HTTP & GRPC python server concurrently on AWS Elastic
1.45 GEEK