How I created a multi-cloud distributed solution with AWS and Azure free tier

Jaime Dantas
Reverse Engineering
9 min readFeb 2, 2020
Photo by Jaime Dantas — Fortaleza — Brazil

In this post, I’ll describe step-by-step how I built an entire distributed solution using only AWS and Azure free tier products. The services I created were scattered throughout both these cloud providers, and they are up and running in production mode 24/7 at this moment. These services were coded in Java and Angular. By the end of this post, you’ll know how to host your own applications in the cloud without spending a penny.

Overview

The solution I created is a software for calculating taxes and fees of financial transactions in the Brazilian stock exchange BM&FBOVESPA (B3).

Overall, this project is composed of 5 services in total:

  • fiiz-tax-frontend: Static website in HTML 5 hosted on GitPages
  • fiiz-tax-ui: Angular 8 application GUI
  • fiiz-tax-authenticator: Spring Boot microservice for authentication and storage
  • fiiz-tax-calculator: Spring Boot microservice for math operations
  • fiiz-tax-database: MySQL database

All these services were created from the ground up and launched into production using only free tiers offered by cloud providers. The GitHub Pages service was also used for hosting the website of this solution. You heard that right, I was able to put on the market a complete business with zero cost.

I’ll use the C4 model for describing the architecture of this project through diagrams and components. If you don’t know what that is, feel free to check the documentation here.

The architecture of this project is shown below.

Container diagram

Below I’ll deep dive into each of these components, and explain how I built my cloud.

Solution

www.fiiztax.com

I’ve decided to create a service called FIIZ TAX which consists of an automated tool for calculating transaction taxes in the Brazilian stock exchange B3. In order to do its prototype, I used the free tiers of AWS and Azure for hosting my services.

All services are up and running 24/7 now, and you can check them out by clicking here.

Website

www.fiiztax.com

The first thing I created was the service’s landing page. Nowadays, building a static webpage is a piece of cake. With so many HTML templates available for free on the Internet, the hard part here was deciding where to host my website. I thought about putting it on a cloud provider, but then I went for the GitHub pages. GitHub Pages is a free and easy way to host your own website as long as they are in a public repository.

This website serves as an entry door for our actual User Interface (UI). The user must click a redirect button to be able to log in and use the Angular frontend.

This is my public repository on GitHub:

Buying a domain

If you prefer, you can buy your own domain name and link it to your GitHub repository. I bought mine on No-IP and enabled HTTPS in the repository settings. When linking it to your GitHub page, select the domain name Type A and point it to the IP of your repository (execute a ping command to find out).

Frontend

The frontend service is called fiiz-tax-ui, and it’s entirely written in Typescript and Angular 8. It performs API calls to the backend service fiiz-tax-authenticator.

Technologies:

  • Angular 8.2.14
  • Bootstrap 4.3.1
  • Angular CLI: 8.3.22
  • Node: 10.13.0

Microservices

I used two microservices for this project. One is in charge of authentication and authorization, and the other one is responsible for performing calculations and math operations.

fiiz-tax-authenticator

This microservice is the main gateway in which our UI communicates with. All requests from the fiiz-tax-ui go through this service.

I am using Spring Security combined with JSON Web Token (JWT) for securing my application. The article below does an awesome job explaining this concept, so I won’t go further in details about this technology.

This service will also perform reading and writing operations in our database which will be explained in a bit.

Technologies:

  • Spring Boot 2.2.2
  • JJWT 0.9.1
  • Spring Boot Security
  • Spring Boot Data JPA

fiiz-tax-calculator

This microservice is the core of all heavy operations. It has a few endpoints which perform math operations based on different inputs. For instance, one of these endpoints receives multiple PDF files and performs mathematical operations in order to calculate the taxes of each individual stock sent by the client. This operation demands a high CPU processing power, so this service needed to be scalable somehow.

Since there is no need to expose these endpoints directly to the internet, the security system used here was based on security token, and it is managed by the fiiz-tax-authenticator.

If you want to know more about its concept, I have a similar microservice available on my GitHub:

One of the dependencies I use was the Swagger interface. This library is used for generating the documentation of Spring Boot services, and it has a UI interface where we can send requests to the APIs with ready-to-use input data.

Technologies:

  • Spring Boot 2.2.2
  • Springfox Swagger 2.9.2

Database

The schema chosen was MySQL. There are a few tables including a transaction one that storages all user transaction history. Since I didn't want to install MySQL on my computer, I created a docker-compose file to run MySQL inside a container.

Architecture

Now it’s time to explain how I got all these services up and running in the cloud for free. I hosted the majority of the services on AWS, leaving only the fiiz-tax-calculator on Azure.

AWS

The first thing you’ll need is an AWS account. After you create one, you’ll have an entire year to enjoy the free tier services offered by Amazon.

As soon as I logged in on my AWS Console, I created a security group for my services. In this security group, I opened the port 443 for HTTPS and 22 for SSL to allow inbound access.

It’s important to set it up a budget limit for your account so you don’t have any unwanted surprises when your credit card bill arrives. In my case, I created a USD 10 limit for using AWS services.

EC2

I hosted both fiiz-tax-authenticator and fiiz-tax-ui services in an EC2 instance. The only option available in the free tier is a t2.micro instance. With this option, you’ll get a Linux Virtual Machine with 1GB RAM and 1 vCPU. I found that this hardware is enough for one Java instance, but you can push the borders and make it work with a couple of services as well. I picked the Ubuntu 18.04 OS for my instance.

As soon as you get your EC2 ready, you’ll need to install all the required software to get your services running. In my case, I had to install Angular, node.js, maven, JDK, Nginx, and Git.

After starting both my services in this instance, I noticed that1 GB RAM is not enough memory to keep them running smoothly. However, they work just fine as long as they are under a low load. With this configuration, I am using almost all the RAM.

AWS EC2 running Angular and Java service

Update: I migrated the fiiz-tax-ui service to the Firebase! I’ve documented the whole thing here:

SSL Certificate

It is pivotal to secure your application with HTTPS. This is because browsers usually block nonsecured connections where the user is required to enter data. Because my application is all about data inputs, I had to secure it over HTTPS.

Since I didn’t want to spend money on this project just yet, I’ve decided to use the Letsencrypt SSL service to get my free certificate. The process is quite simple, and it doesn’t require many steps at all. Below you can find the tutorial to get yours installed on your EC2 instance as well.

Nginx

After installing the SLL Certificate, your EC2 instance is ready to go. The only thing left is configuring the routes of Nginx. Bear in mind this is important since we don’t want to expose hidden endpoints to the Internet. Also, remember that only port 443 is opened, so all traffic needs to flow through this way. Thus, we’ll use Nginx to redirect some routes to different services. In order to do so, we need to change the Nginx default file.

cd /etc/nginx/sites-available
sudo nano default

Now you’ll need to add all the routes you have. In my case, I’m running two services, and I want that all the routes but the /tax/ and /auth/ redirect to port 4200 where our UI is running.

location / {
proxy_pass http://localhost:4200;
}
location /tax/ {
proxy_pass http://localhost:8081;
}
location /auth/ {
proxy_pass http://localhost:8081;
}

Finally, your EC2 instance should be ready for the next step.

RDS

AWS RDS is the service offered by Amazon for relational databases. Since we’re using MySQL, I chose this option because it’s included in the free tier. The only concern when installing your schema is to remember to associate the same security group of your EC2 instance or you can create a new one and add it to your EC2 instance as well.

After creating your RDS instance, it’s time to point your EC2 microservice to your RDS database. I also run some SQL scrips for creating my schema and tables from the EC2 instance using the MySQL Client. You can either connect to your RDS server from your computer using any database management software or install the MySQL client on your EC2 instance as shown below.

apt-get install mysql-client

Now your entire ecosystem is almost ready. This should be enough to get your service online if you’re using only AWS.

Azure

I’ve decided to host my fiiz-tax-calculator service on Azure because it offers such an awesome free tier service. Not only do you get VM for using as you wish, but also USD 200 for trying it out a bunch of other cool services. The sky is the limit here. Anyways, as always, the first thing I created was a security group. Although I’m exposing my endpoints with HTTPS on AWS, I used HTTP on Azure to make life easy.

VM

Initially, I went for a VM on Azure. My choice was entirely based on how fast I could get my application up and running somehow. Believe you or not, I was able to create my account and set up all my Azure cloud in just 45 minutes, so it’s quite simple and easy to work with it.

I only opened port 80 for HTTP traffic, and the authorization token is used for securing my application. I am using also using Ubuntu 18.04 OS on my VM instance. Since I am only running a Java microservice, the dependencies I installed were JDK, maven, and Git.

Azure / AWS communication

Conclusion

This post was intended for those who wanted to try it out the public cloud for free. All cloud provides offers free tier services for at least one year, and you can host your first application in the cloud in just a few steps.

I hope the article helped you to understand how AWS and Azure free tier works, and how to create your own services and make them online all over the internet for free.

If you have any questions, don’t hesitate in reaching me for further clarification.

Thanks for reading it!

www.jaimedantas.com

--

--