name :bishweashwar-ec2
owner :[email protected]
team :mle
project :aws-training
-
Create your instance (I preferred Ubuntu Server 22.04 LTS (HVM) ,SSD Volume type ;as Amazon Machine Image- AMI)
-
After successfully creating your instance , connect to your instance. I used CLI for this.
-
Paste the below command where your key is stored. ssh -i "EC2.pem" [email protected]
You can get this command in after creating your instance and clicking on Connect Tab then SSH client.
-
Sometimes you will get permission denied (0644 error). Use the below command
chmod 400 EC2.pem
For other error google it.
-
After this you need to install every package required by your after inside instance.
-
Use the folloing command:
i. sudo apt-get update.
ii. sudo apt-get install python3.
iii. sudo apt-get install python3-pip.
iv. pip3 install flask.
v. sudo apt-get install nginx (python web server).
vi. sudo apt-get install gunicorn (python web server getway interface or wxgi )
Now you have to setup AWS configuration also
vii. sudo apt install awscli.
viii. aws configure (insert your key, id region) & after this open credentials inside .aws folder and save your profile name inside that.
ix. cd ~/../../etc/nginx/sites-enabled/
x. sudo nano flaskapp (for configuring nginx server)
server {
listen 8085; //Use any port from which you want to get traffic from internet . //By default 80 is their but for assignment purpose I have used 8085 (TCP) //In Security group of your instance you also need to add 8085 port. server_name 54.152.120.192; //Paste your Public IP here location / { proxy_pass http://127.0.0.1:8000; } }
save the file (Ctrl + X -> press ENTER key)
xi. sudo service nginx restart.
xii. Now get inside Software folder. If it is in local machine then use below command to transfer into EC2 instance:
exit (to stop instance)
scp -i EC2.pem -r directory_location/ [email protected]:~/.
scp -i EC2.pem file_location/ [email protected]:~/.
xiii. Connect to your instance. Get into your software folder and run below command (Name your software file app.py)
gunicorn3 app:app
xiv. Now copy your public IP from instance page and run it
xv. Close the server using Ctrl + C
xvi. nohup gunicorn app:app & press ENTER key
After running above command you need not run server in background always.