How to Effortlessly make a Cloud Deployment of Multi-Language Project? | #100
Problem Statement
Build automation services in multiple languages(Python and TypeScript) and deploy it into the production so others can access automation without any difference.
Automation is nothing but performing tasks with less or more time without any human intervention. It involves both 𝐬𝐢𝐦𝐩𝐥𝐞 𝐬𝐜𝐫𝐢𝐩𝐭𝐬 and 𝐜𝐨𝐦𝐩𝐥𝐞𝐱 𝐬𝐞𝐫𝐯𝐢𝐜𝐞𝐬.
Simple scripts are useful if the task is 𝐝𝐢𝐫𝐞𝐜𝐭 and involves simple logic. Example: Extracting phone number from the Address.
Over a period of time 𝐬𝐨𝐟𝐭𝐰𝐚𝐫𝐞 𝐛𝐞𝐜𝐨𝐦𝐞𝐬 𝐬𝐨 𝐜𝐨𝐦𝐩𝐥𝐞𝐱 you 𝐧𝐞𝐞𝐝 other software to manage one that you have built.
Today, 𝐀𝐈 𝐜𝐡𝐚𝐭𝐛𝐨𝐭𝐬 will give you the Python or node scripts if you 𝐚𝐬𝐤 the 𝐫𝐢𝐠𝐡𝐭 𝐪𝐮𝐞𝐬𝐭𝐢𝐨𝐧.
I prefer TypeScript & nodejs for some tasks & to some it's Python.
How to differentiate which language to use for which tasks? You can achieve any of the tasks with any of the programming languages. But, you need to consider the 𝐭𝐢𝐦𝐞 and 𝐞𝐟𝐟𝐨𝐫𝐭 involved in developing it. Because at the end of the day, it is 𝐚𝐥𝐥 𝐚𝐛𝐨𝐮𝐭 𝐭𝐡𝐞 𝐩𝐫𝐨𝐛𝐥𝐞𝐦𝐬 that you are solving.
Python is the go-to language for manipulating 𝐭𝐚𝐛𝐮𝐥𝐚𝐫 𝐝𝐚𝐭𝐚. Many 𝐛𝐚𝐭𝐭𝐥𝐞-𝐭𝐞𝐬𝐭𝐞𝐝 libraries exist which are difficult to find in other languages.
If you want to build an async service that is highly scalable then TypeScript & node is preferred.
My cloud stack to solve this problem is AWS, nginx, and pm2. It does the job.
For the view layer, you can choose any technology like React, EJS, or Jinja. In my case, I used EJS, as the automations that I built involved more backend logic than the frontend.
Both the nginx and pm2 processes are within the ec2 instance and not outside of it. The above image is just to understand the process.
Once you have ec2 up and running, you can start configuring the nginx. I selected t3a.medium with 50 GB storage for my application.
How to configure nginx?
I have written about it in my weekly techletter #97.
Learn how to configure nginx, because this will make your life a lot easier for deploying applications on the cloud.
With the kind of deployment shown in the above image, you can quickly build independent automation without any language barriers.
It would really help you if you had an architecture regarding the code organization. Below is my way of doing it
src/
├── python/
│ ├── apps/
│ │ ├── py_plugin_1/
│ │ ├── py_plugin_2/
│ ├── common/
│ ├── config/
│ └── tests/
├── typescript/
│ ├── apps/
│ │ ├── ts_plugin_1/
│ │ ├── ts_plugin_2/
│ ├── common/
│ ├── config/
│ └── tests/
├── shared/
│ ├── schemas/
│ ├── docs/
│── scripts/
Once you have built your service, now it is time for you to buy a domain (if required). Otherwise, you can make use of the public IP of ec2 to test your deployment.
Once you have configured the nginx you can now use pm2 to start TypeScript and Python applications on different processes.
pm2 start “COMMAND TO RUN TypeScript PROJECT” —name TS_PROCESS_NAME
pm2 start “COMMAND TO RUN Python PROJECT” —name PY_PROCESS_NAME
Every week I write techletters that help software engineers learn something new.
If you gained something from this article then consider subscribing to this newsletter & share this article with other software engineers you know (this would mean a lot to me)