[TIL] Deploy AI Model Developed w/ Flask API Using AWS EC2 & Connect to Nest.js Project
06/20/23
![[TIL] Deploy AI Model Developed w/ Flask API Using AWS EC2 & Connect to Nest.js Project](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1688371536260%2F4df56663-ae80-4f6f-a316-7e0911458029.png&w=3840&q=75)
Using AI Model for Emergency Level Prediction: EC2 Server Scale Up
t2.micro (free tier)

๐ซ Killed: Indicates that the process was terminated by the operating system. โ
pip install tensorflowwas killed by the OS. It was interrupted due to insufficient memory on the AWS EC2 free tier instance.
t3.small

๐ซ Similar to t2.micro, it was killed.
t3.medium

โ
pip install tensorflowsuccessfully installed TensorFlow. In the case of the Flask API, it does not require GPU since it loads a pre-trained model for predicting emergency levels. Therefore, a CPU EC2 instance is sufficient.
Additional commands executed on the EC2 instance / Installed modules:
sudo apt updatesudo apt install python3-pipsudo apt-get install python3-venvsudo apt-get install default-jdkโ JDK installation for usingkonlpysudo pip install konlpypip install intel-tensorflow==2.12.0(Installed to address version-related errors)pip install -U keras_applications==1.0.6 --no-depspip install -U keras_preprocessing==1.0.5 --no-deps
Connecting to the EC2 Server Instance
Port forwarding
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 5000
My apologies for the mistake... I kept accessing the t3.small IP address instead of t3.medium. It was a silly mistake, not a troubleshooting issue.
Running the Flask server in the background
nohup python -uapp.py&โ Run in the backgroundtail -f nohup.outโ Check the logslsof -i :5000โ Check the PIDsudo kill -9 [PID]โ Terminate the running process
![[์ฝํ
] ๊ทธ๋ฆฌ๋ ๋ฌธ์ - ๋ฌด์ง์ ๋จน๋ฐฉ ๋ผ์ด๋ธ](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1712215455263%2F1ac1f35a-8862-4e42-8d0c-e2bea01e04c0.png&w=3840&q=75)
![[์ฝํ
] Bfs ํ ๋งํ](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1709032619170%2F70056896-c857-444b-9c99-45bfcb466806.png&w=3840&q=75)
![[์ฝํ
] Dfs ๋ฌธ์ ์ ํ - ๊ทธ๋ํ ๋ด์์ ๊ตฌ๋ถํ์ฌ ์นด์ดํธ ํ๊ธฐ](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1709019361383%2Fb0585d72-c808-4169-83a9-2724f312e927.png&w=3840&q=75)
![[์ฝํ
] DFS vs BFS](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708971211123%2F71f9386c-6a62-43b2-a602-4d084c24d6cf.png&w=3840&q=75)
![[์ฝํ
] ์ฌํ๊ฒฝ๋ก](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708971251412%2F27ce72ed-8ee7-4d13-a02f-ff4bbe50c4be.png&w=3840&q=75)