Wednesday, September 29, 2021

Cloud-native App on AWS to contact trace passengers in Victoria during Covid

How I developed a cloud-native web app on AWS to help contact trace public transport passengers in Victoria during COVID-19

Finally I managed to allocate a night to write about a small project I developed few months back (June, 2021 to be precise) based on a problem I was thinking about for a while. This article explains how I developed a cloud native web app on AWS to help contact trace public transport passengers in Victoria, Australia during COVID-19.

I have organized this article into 4 sections.

  1. Background Story
  2. The Solution
  3. How it works
  4. The Implementation

To provide a little bit of context, I would like to mention the background story of this project.

Background Story

I am a final year post grad student studying Master of Information Technology at RMIT University Melbourne, Victoria, Australia. I took an elective course last semester on ‘Cloud Computing’ and the final assignment was to develop an application which uses a mix of cloud services from a preferred cloud service provider. The interesting part of this assignment was that we were given the freedom to develop an app of our choice (Hello imagination! 😉).

Since we are living in a pandemic (at least by the time I am writing this article), I thought of developing something to help contact trace passengers travelling on public transport in Victoria. Since I use public transport like many others, I was thinking how hard it must be to trace potential COVID-19 infected passengers and the close contacts in public transports. Hence, I made this task my mission to solve using cloud computing.

The Solution

After analysing the Victorian public transport system which is primarily consists of trains, trams and busses; I came up with a solution and named it TraceX’, a cloud native POC (proof of concept) web application to help contact trace public transport passengers in Victoria during the COVID-19.

Public transport passengers can register themselves in TraceX using their email address. Then users can view or search all the public transports available in the system and click ‘Subscribe Commute’ on the public transports user has travelled in and get alerts (Email notifications to the users stating the potential risk, if a COVID-19 virus affected passenger was detected in that particular public transport) for affected-transports users have travelled.

When the administrators of the TraceX receive verified information on COVID-19 affected public transports from the health officials, admins can mark the relevant public transport as ‘Unsafe’, resulting the users who are subscribed to that public transport would get alerted. Alerts would be shown in users’ dashboard and also sent to their emails immediately.

How it works

TraceX is a web application which can track passenger trips taken on public transports by helping to maximise the efficiency of contact tracing. Since it’s a POC, the functionality is quite simple.

The UI and UX aren’t the perfect. I was able to spend only 4 days from drawing the initial wireframes, design the AWS architecture and to finalize the implementation. 😅

User Features

TraceX Login page
Users can view or search all the transports available in the system and click ‘Subscribe Commute’
Users can view the subscribed transports. This page only shows the public transports that the user has taken. The user also can click ‘Unsubscribe Commute’ to remove a transport
Email alert sent to the user if the user has travelled in a COVID-19 exposed public transport

Administrator Features

Summarised data dashboard visualization for Administrators
Add basic data on public transports for the application
View all public transports including the status and the number of passengers. Action to mark the transport Safe or Unsafe

The Implementation

I’m sure most of you are interested on this section of the article and eagerly waiting to have a look at the architecture.

Just before I dive into the detailed implementation, feel free to post your thoughts or suggestions in the comments section or drop me a message.

Programming stack

Django, which is a Python based web framework was used as the backend framework of the application while AngularJS was used as the frontend framework. Boto3, which is the AWS SDK for Python was used to integrate the application with the AWS services.

AWS Architecture

Let’s have a look at the AWS architecture of TraceX.

AWS architecture of TraceX

It is important to mention that the entire application was built using an AWS Free Tier account 😍. Architecture isn’t much complex to implement whilst I tried to limit the AWS services used, due to the time constraints of the implementation phase.

I will try to briefly explain the AWS services I have used in TraceX, how I did the implementation and integration.

  1. Amazon Elastic Beanstalk (EB)

AWS Elastic Beanstalk was used to deploy the Python based web application to the AWS infrastructure, interacting and deploying through the EB Command Line Interface. I referred the below documentation provided by the AWS.

1.1 Initially the Django project was set up locally and created a virtual environment.

1.2 Configuring the Django application with Elastic Beanstalk.

To configure the Django application with the Elastic Beanstalk, a directory named ‘.ebextensions’ was created and a file named ‘django.config’ was created.

django.config file content

1.3 Deploy the web application using the EB CLI.

Using the EB CLI, a Beanstalk environment was created to deploy the application.
Once the environment was deployed. The application was deployed using the ‘eb deploy’ command.

1.4 Update the Django Project

Run the Django migrations and re-deploy the application.

Deployed Beanstalk Environment

2. Amazon Relational Database Service (RDS)

The TraceX application uses a relational database to store the public transport details, user tracking information, user subscriptions details. A PostgreSQL engine was used with the AWS RDS instance which was created using the AWS EB and connected with the Elastic Beanstalk environment to make the database instance elastically scale with the number of requests.

The RDS was created and integrated referring to the following documentation.

Since the application was deployed using the AWS Beanstalk, the RDS instance was configured and integrated through the Beanstalk environment (It is not a must to configure the RDS through the Beanstalk, you can provision the RDS service separately as well). This was created by adding a database instance from the Beanstalk environment Configurations.

A db.t2.micro instance with PostgresSQL engine was used in the TraceX. Since the RDS was created through the Beanstalk environment, a VPC security group was added with the RDS instance.

The following configurations were done in the Django project to connect with the RDS instance

3. AWS Lambda

There are 2 lambda functions that are being used in the TraceX application. Two of our functions which are to verify the user email using Amazon Simple Email Service (SES) and to send emails of COVID-19 alerts to users were implemented using Lambda functions. Both Lambda functions were written in Python and connected to API Gateways as the triggers for the Lambda services.

3.1 Created a Lambda function named ‘TraceXNewUserEmail’.

This is triggered using an API Gateway, which then would send the email of a new user that’s being registered with the system. Then the Lambda would use the SES to send a verification email to the user.

3.2 The second Lambda function is named ‘TracexSendUserEmail’.

This Lambda is triggered using an API Gateway when an Administrator of the TraceX changes the Alert status of a public transport in the system. Emails of all the users who are subscribed to that particular transport then would be sent to the Lambda function and using SES, alert emails would be sent to the users.

4. Amazon API Gateway

Amazon API gateway was used as the triggers for both Lambda functions. Two API gateways for each lambda were created. Both API types were REST API using POST methods.

API Gateway named ‘TracexSendUserEmail-API’ created for the TracexSendUserEmail lambda function.
TracexNewUserEmail-API implementation was used in the Django application

5. Amazon Quicksight

Amazon Quicksight was used in the TraceX application to provide a quick overview of the COVID-19 affected public transports and users in a dashboard-based visualization. This feature enabled the administrators of the TraceX to identify potentially significant public transports, the number of potential COVID-19 infected people. The Amazon Quicksight dashboard was directly linked with the AWS RDS in the application.

New RDS Data Source Connection

Since the Quicksight dashboard needs to be integrated with the TraceX Admin Dashboard, application URLs need to be whitelisted through the Domains and Embedding section of the Quicksight. An Enterprise edition version of Quicksight was used since the dashboard needed to be embedded to an external website.

TraceX Admin Dashboard developed using QuickSight
After the Quicksight dashboard was published, an embedding URL was retrieved using the following code written in the Django application.
The above code demonstrates how the published dashboard was embedded to the administrator page in the frontend

6. Amazon Route 53

The domain (tracex.link) for the application was bought using the AWS Route 53. Then a hosted zone was created with reference to the domain name and the name servers. In order to connect the Beanstalk application with the domain name, ‘A’ record was created in the hosted zone.

7. Amazon Certificate Manager

ACM was used to obtain the SSL certifications for the purchased domain.
After the SSL certification was issued by ACM. It was needed to be connected with the Load Balancer of the Beanstalk environment.

8. Amazon Simple Email Service

Since the SES is a sandboxed version in TraceX, when the users get registered with the system, an email would be sent out to them using a Lambda function. Once the user verifies the email, alerts would be sent out for the users.

SES Console
Following code is written in the Lambda function to verify the email of a user.
Following code is written in the Lambda function to send Email alerts for the users.
The above email will be sent to the user email inbox from the AWS Simple Email Service once a user gets registered with the system.


from Hacker News https://ift.tt/3B3V6Is

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.