Skip to content

Python web app source code for the AWS UserGroup Dubai “2021 Container Series - Building Containers” workshop

Notifications You must be signed in to change notification settings

yalo/aws-ug-dbx-2021-building-containers-workshop-python-app

 
 

Repository files navigation

Python web app

Proof-of-Concept (PoC) application that returns a name. It is indented to be called by another application that composes a "Greeting name!" output.

For example for "Hello world!" this app would be the one providing the "world".

Architecture diagram

Commands

Since Python is an interpreted language, we need to run in an interpreted local virtual environment. For this, we use Poetry. To install Poetry:

pip install poetry

Dependencies are defined in pyproject.toml, poetry.toml, and poetry.lock. TO install the dependencies:

poetry install --no-dev

To build the application:

# Nothing to build, Python is an interpreted language

To run the application, in the virtual environment:

poetry run gunicorn -b0.0.0.0:5002 app:app

To run a container with the application:

docker run --interactive --tty --rm \
  --publish 5002:5002 \
  YOUR_IMAGE_ID_HERE

Endpoints exposed by the application:

# curl -v http://localhost:5002
  *   Trying ::1...
  * TCP_NODELAY set
  * Connected to localhost (::1) port 5002 (#0)
  > GET / HTTP/1.1
  > Host: localhost:5002
  > User-Agent: curl/7.64.1
  > Accept: */*
  >
  < HTTP/1.1 200 OK
  < Server: gunicorn
  < Date: Thu, 1 Apr 1000 10:10:09 GMT
  < Connection: close
  < Content-Type: application/json
  < Content-Length: 21
  < X-Reply-Service: greeter-service
  < X-Version: dev
  < Access-Control-Allow-Origin: *
  <
  * Closing connection 0

  {"greeting": "hello"}

# curl -v http://localhost:5002/status/alive
  *   Trying ::1...
  * TCP_NODELAY set
  * Connected to localhost (::1) port 5002 (#0)
  > GET /status/alive HTTP/1.1
  > Host: localhost:5002
  > User-Agent: curl/7.64.1
  > Accept: */*
  >
  < HTTP/1.1 200 OK
  < Server: gunicorn
  < Date: Thu, 1 Apr 1000 10:10:10 GMT
  < Connection: close
  < Content-Type: application/json
  < Content-Length: 38
  < X-Reply-Service: greeter-service
  < X-Version: dev
  < Access-Control-Allow-Origin: *
  <
  * Closing connection 0

  {"status": "Greeter service is alive"}

# curl -v http://localhost:5002/status/healthy
  *   Trying ::1...
  * TCP_NODELAY set
  * Connected to localhost (::1) port 5002 (#0)
  > GET /status/healthy HTTP/1.1
  > Host: localhost:5002
  > User-Agent: curl/7.64.1
  > Accept: */*
  >
  < HTTP/1.1 200 OK
  < Server: gunicorn
  < Date: Thu, 1 Apr 1000 10:10:11 GMT
  < Connection: close
  < Content-Type: application/json
  < Content-Length: 40
  < X-Reply-Service: greeter-service
  < X-Version: dev
  < Access-Control-Allow-Origin: *
  <
  * Closing connection 0

  {"status": "Greeter service is healthy"}

About

Python web app source code for the AWS UserGroup Dubai “2021 Container Series - Building Containers” workshop

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 83.4%
  • Shell 14.3%
  • Dockerfile 2.3%