How Do I Deploy A Python Flask Web Application On Ec2?

Asked 11 months ago
Answer 1
Viewed 170
1

This is an instructional exercise to assist you with facilitating your python jar application onto the EC2 occasion. I will make sense of how for make an EC2 case and furthermore an example cup program!

Prior to bouncing into the technique let me give a short presentation about Jar and EC2.

Python Flask :

Python Jar is a miniature web structure which is utilized for fast web improvement. Jar is exceptionally basic and simple to execute. Jar can be handily brought into python project and their documentation is truly useful to get everything rolling.

Amazon’s EC2 :

Amazon Flexible Process Cloud (EC2) (in fact it ought to have been EC² Haha) is an IaaS(Infrastructure as a Help) distributed computing administration given by Amazon. EC2 helps in sending applications by giving a web administration through which a client can boot an Amazon Machine Image(AMI) to design a virtual machine called Cases.

System:

To begin with, we should make the carafe program. A jar contains a python code that contains the endpoints. The endpoints can be a capability that can run and return a reaction when called. On the off chance that the return reaction is a HTML document, it ought to be kept in a layouts envelope.

Here is the python code for cup


'''pip3 install flask'''
from flask import Flask,render_template

app = Flask('__name__')


@app.route('/')
def home():
    return render_template('home.html')

@app.route('/endpoint')
def endpoint():
    return "This is an end point. You can call send or receive requests by calling this end point."

@app.route('/linker')
def linker():
    return render_template('link.html')

if __name__ == "__main__":
    app.run(host="0.0.0.0",port=5000)
    #app.run(debug=True) #can alter host and port number here. Right now the default host is localhost and port is 5000

Here is the Github connect for the web layouts: https://github.com/saro-mano/Flask_Medium.git

Presently, we should leap to the AWS part.

Step 1: Sign Up

So in the event that you haven't pursued an AWS account, do join cause it is free. You can join as a root client so you can have full command over your control center.

Step 2: Launch EC2 and choose an AMI

When you are in AWS console, click on "Send off a Virtual Machine with EC2". I will involve Linux for this task. Thus, I pick Amazon Linux 2 AMI (HVM), SSD Volume Type[64 bit].

Step 3: Choose Instant Type

For our undertaking, a broadly useful example with 1 GiB memory is adequate. Along these lines, I'm picking this:

After this step, click on survey and send off. Be that as it may, assuming that you wish you can arrange example type, security, add capacity, add labels. I will leave them with the default arrangement.

Stage 4: Sending off Example

When you click the send off example you would be provoked requesting to create a key pair. This is a significant stage and the key you produce from this step will assist you with interfacing with the EC2 example from the framework you work on.

Read Also: How to scrape data from a website using Python for beginner?

Answered 11 months ago Rajesh KumarRajesh Kumar