Application components – Running Containers in AWS

Mike Naughton | June 1st, 2022


This is supposed to bea long-running application that will primarily consist of two containers – a web application and a database. We can define them in their respective container definitions, which can then both be mapped to a single task definition. ECS offers the service construct to manage such long-running applications, so we will use it to expose the application container to the outside world on port 5000. As a best practice, we will front the application with an Application Load Balancer and the ECS service will take care of registering/de-registering the containers as part of their life cycle.

To build the core of our application, we will use the Python-based Flask framework. Among many other features the web application framework offers, we are mainly interested in static file support, template rendering, and HTTP request/response management. We will see these code snippets in action in the following sections. The application frontend will be rendered using HTML and Bootstrap. All the user interactions (creation or deletion of tasks) will be mapped to the corresponding APIs in Flask:

  • Frontend (HTML and Bootstrap): Using standard HTML elements such as tables and forms, we allow the users to interact with the application with an easy-to-use interface where they can create, categorize, and delete tasks. Each action on the web page is mapped to backend APIs that we manage with Flask.
  • Backend (Flask framework): Flask offers easy-to-implement HTTP routing mechanisms using the @app.route function decorators. We will use them to handle the GET and POST requests originating from our application. As you can imagine, these APIs will further interact with the database layer since we want to persist all the tasks and avoid any data loss.
  • Data persistence (MongoDB and EFS): MongoDB is a NoSQL database program that simplifies the process of storing, retrieving, and manipulating JSON-based documents. We will use the official MongoDB Docker image to run a container in ECS. Since container storage is ephemeral, we will mount an external EFS volume using ECS task definition capabilities so that no data is lost, should a container require a restart for any reason. Managed services such as ECS make this very easy for the user by automatically mapping such volumes in the container instances. Otherwise, doing something similar in an EC2 instance manually requires some scripting effort.

Similar to what we have used for the command- line utilities required in all exercises so far, I have published the bundled application code for the test application in a Docker image, in the public DockerHub registry. This should save you some hassle around building and hosting this image onyour own. Refer to Figure 7.3 for a visual understanding of how the application containers hosted in ECS interact with other infrastructure elements:

Figure 7.3 – Application components and the workflow of the To-Do List Manager application hosted on ECS

We intend to use CDK to deploy our infrastructure and application elements. So, let’s discuss the stack components we will require.

Leave a Reply

Your email address will not be published. Required fields are marked *