Python Microservices Application: Video to Audio Converter
In this text, we’re going to create a Python Application the place we’ll use Kubernetes on Amazon EKS, Helm Charts, MongoDB, PostgreSQL, RabbitMQ and Docker.
Users will provoke a request by the API Gateway. The Gateway supplies three endpoints: Login, Upload, and Download.
- Initially, the consumer logs in, and the API Gateway communicates with Postgres to validate the credentials. Upon profitable authentication, a JWT token is generated, granting the consumer permission to add a video.
- The video can be saved within the rabbitMQ which then will switch to converter.
- After changing, the mp3 information can be saved in mongoDB which is once more deployed by Helm Charts.
- After changing the audio, we’re gonna get a notification on our electronic mail id by notification service, you can even obtain it by the obtain half.
- We will even have Dockerfiles to create docker pictures for every service and we’ll push the docker pictures to DockerHub.
Note: It is assumed that you’ve got Helm, Python, AWS CLI and kubectl put in and configured in your native system. Check this web page for Helm, this web page for Python, AWS CLI for right here and at last click on right here for Kubectl set up.
Let’s Begin!!!!
Part 1: Git Clone and Cluster Creation
We are going to clone the repository into our native and create the EKS cluster as a result of it takes a bit of little bit of time.
To clone, do
git clone https://github.com/Berkay542/python-microservices.git
Note: We are going to wish eksCluster IAM Role and AmazonEKSNodeRole as a way to create the cluster. To be taught extra about Amazon EKS, you possibly can go forward and watch this video.
- Your EksCluster function ought to have 2 permissions insurance policies: CNI_Policy and Cluster Policy; EKSNodeRole ought to have the 4 permissons: AmazonEKS_CNI_Policy, AmazonEBSCSIDriverPolicy, AmazonEC2ContainerRegistryReadOnly, AmazonEKSWorkerNode insurance policies.
- Now, go forward and create the cluster with default add ons however connect the roles we’ve got simply created. Once the cluster is created, we’re going to create a NodeGroup for our cluster.
- When creating the NodeGroup, make all of it default besides we’re solely going to wish 1 Node for our cluster. After the node has been created, we’re going to join our cluster utilizing AWS CLI.
Connect to the cluster with terminal:
aws eks update-kubeconfig --name <NameforyourEKS> --region us-east-1
Part 2: MongoDB, PostgreSQL and RabbitMQ installations, Setups
go the place your Github repository is and cd into /Helm_charts/MongoDB and run the command: | helm set up mongo . | to put in mongo by helm.
- Helm is a bundle supervisor for Kubernetes that simplifies the deployment of containerized purposes.
- We can be utilizing Persistent Volumes for our sources. To see that, you possibly can run: kubectl get pv
- you possibly can run kubectl get pods to see the pod that we’ve got simply created.
- Cd into /Helm_charts/Postgres
Note: Change the e-mail within the init.sql and likewise /src/notification-service/manifest/secret.yaml file. Google doesn’t mean you can use your precise password elsewhere so you’ll must create a app pasword for this mission.
- run helm set up postgres . and verify the sources afterwards.
- Now, we’re going to join our mongoDB with:
mongosh mongodb://<username>:<pwd>@<nodeip>:30005/mp3s?authSource=admin
- If you get an error that claims mongosh not discovered, we have to set up sh for mongodb, do “ brew set up mongosh” then exit.
Note: You additionally have to obtain Homebrew as a way to set up command traces. Install right here.
- nodeip means the general public ipv4 tackle for the ec2 occasion that EKS has created for us.
- for us to attach, we have to have the port 30005 open in our safety group since MongoDB runs on port 30005. You can see that while you run the command “ kubectl get svc ”
- In reality, we are able to open all of the ports we’re going to want to avoid wasting us time that are: 30002, 30003, 30004 and 30005.
- 30002 is for our Gateway, 30003 for Postgres, 30004 for RabbitMQ and 30005 for MongoDB.
Note: Anytime you face a trip problem, it is because you don’t have your ports open in your safety group.
Connect to your Postgres Database with:
psql 'postgres://<username>:<pwd>@<nodeip>:30003/authdb'
- cd into /Helm_charts/Postgres, copy what’s within the init.sql file and paste it into postsql database, enter.
- What we did right here was that we created a desk within the Postgres database to validate the credentials.
- MongoDB and Postgres databases are created and now let’s go and deploy RabbitMQ.
RabbitMQ is utilized to facilitate the switch of the uploaded video information to the converter service for additional processing.
- cd into RabbitMQ and run “ helm set up rabbit .”
- go forward and entry to your RabbitMQ website with <yournodeip>:30004
- by default, username and password is “visitor”.
- click on queues and create a brand new one, sort is basic and the identify is “mp3” and create
- create an one other queue named as “video”
This is all we want from the RabbitMQ website for now.
Part 3: Deploying our Microservices
Let’s go and deploy our microservices individually.
- cd into /src/auth-service and we’re going to create our docker pictures by Dockerfiles that I’ve written with the command:
docker construct -t auth .
- Make certain your Docker Daemon is operating. ( Docker Desktop )
- verify your pictures with “ docker pictures”
- let’s push our newly created picture to our DockerHub
- sign up to your Dockerhub account with the command: Docker login
- create a brand new repo in your dockerhub named auth then run the command:
docker tag auth:newest <dockerhubusername>/auth
docker push <dockerhubusername>/auth
Note: Make certain to do the identical factor with your entire companies: auth-service, converter-service, gateaway-service, notification-service.
These pictures are getting used within the manifest recordsdata, so don’t neglect to vary your credentials within the manifest recordsdata!!!
- Once you pushed all the photographs to your Dockerhub, cd into /src/auth-service/manifest. and run “ kubectl apply -f .” to create the sources we’ve got within the manifest recordsdata.
- Apply the identical command in each manifest folder path.
- I’ve a video offered within the belongings folder, so we’re going to convert this video to a mp3 format.
Once we’ve got deployed all the things, we’re going to login to our PostgreSQL with:
curl -X POST http://nodeIP:30002/login -u <electronic mail>:<password>
- The output is your JWT Token, you must decode it in a base64 format with:
echo "<yourJWTtoken>" | base64 -d
- Now we’re going to add our video with:
curl -X POST -F 'file=@./video.mp4' -H 'Authorization: Bearer <JWT Token>' http://nodeIP:30002/add
- You ought to see successful message within the command line
- verify your electronic mail for the id which we’re going to use to get the mp3 that’s saved in our MongoDB
This the endpoint the place it downloads the mp3 file into our belongings file.
curl --output video.mp3 -X GET -H 'Authorization: Bearer <JWT Token>' "http://nodeIP:30002/obtain?fid=<Generated fid>"
Congratulations!!, go and verify the downloaded file!
Rest assured, many have encountered the identical errors prior to now that you’re dealing with proper now. You are greater than welcome to make use of https://www.google.com/. and https://stackoverflow.com/.
In Plain English
Thank you for being part of our neighborhood! Before you go:
- Be certain to clap and observe the author! 👏
- You can discover much more content material at PlainEnglish.io 🚀
- Sign up for our free weekly publication. 🗞️
- Follow us: Twitter(X), LinkedIn, YouTube, Discord.
- Check out our different platforms: Stackademic, CoFeed, Venture.
Python Microservices Application: Video to Audio Converter was initially printed in AWS in Plain English on Medium, the place individuals are persevering with the dialog by highlighting and responding to this story.
HI-FI News
through AWS in Plain English – Medium https://ift.tt/xY4rnCM
November 9, 2023 at 02:39AM
-
Product on sale
Audiophile Vinyl Records Cleaning BundleOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Product on sale
Easy Start Vinyl Records Cleaning KitOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Vinyl Records Cleaner Easy Groove Concentrate€34.95 incl. VAT -
Easy Groove Super Set€199.00 incl. VAT -
Easy Groove Enzycaster – vinyl records prewash cleaner€34.95 incl. VAT -
Easy Groove Extreme MK. II- vinyl records prewash cleaner€45.00 incl. VAT -
Vinyl Records Cleaner – Easy Groove Virgin Concentrate€35.00 incl. VAT -
Easy Groove Spray&Wipe vinyl records cleaner€34.95 incl. VAT








