# How To Deploy Python Application In AWS?

The application by harnessing the capabilities of AWS. AWS, a leading cloud computing platform, offers a wide range of services to help developers build, deploy, and manage applications at scale EC2. It provides scalable computing power in the cloud, allowing developers to scale quickly or down depending on application demand. We will use the EC2(Elastic Compute Cloud) service provided by AWS to make our server and run our application onto this server.

## Why To Deploy Python Applications On AWS?

* **Scalability:** [**AWS**](https://www.geeksforgeeks.org/aws-tutorial/) provides a scalable [**infrastructure**](https://www.geeksforgeeks.org/aws-infrastructure/), allowing your [**Python**](https://www.geeksforgeeks.org/python-programming-language/) application to easily handle multiple tasks.
    
* **Elastic Beanstalk:** [**AWS Elastic Beanstalk**](https://www.geeksforgeeks.org/introduction-to-aws-elastic-beanstalk/) is a [**Platform-as-a-Service (PaaS)**](https://www.geeksforgeeks.org/platform-as-a-service-paas-and-its-types/) offering that simplifies the deployment and management of Python applications.
    
* **Reliability and Availability:** AWS offers global connectivity across data centers, ensuring its high level of reliability for your Python application.
    

## **Step-By-Step Guide To Deploy Python Applications In AWS**

**Step 1:** Log in with [**AWS Account**](https://www.geeksforgeeks.org/amazon-web-services-setting-up-an-aws-account/) with your credentials and Navigate to [**AWS Management Console**](https://www.geeksforgeeks.org/aws-management-console/).

**Step 2:** After signing in you will land on the AWS Management Console page and search for [**EC2**](https://www.geeksforgeeks.org/what-is-elastic-compute-cloud-ec2/) as shown below.

![AWS Console](https://media.geeksforgeeks.org/wp-content/uploads/20240224211955/1.png align="left")

**Step 3:** This will land you on [**Amazon EC2**](https://www.geeksforgeeks.org/what-is-elastic-compute-cloud-ec2/) dashboard from there select **instances** from left menu.

![EC2 Dashboard](https://media.geeksforgeeks.org/wp-content/uploads/20240224211956/2.png align="left")

**Step 4:** From top right, select **Launch instances** this will allow us to make [**EC2 instance**](https://www.geeksforgeeks.org/amazon-ec2-creating-an-elastic-cloud-compute-instance/) (server). This server will contain all the necessary files which you need to deploy your application.

![Launching Instances](https://media.geeksforgeeks.org/wp-content/uploads/20240224211957/3.png align="left")

**Step 5:** Give name to your server and select [**OS**](https://www.geeksforgeeks.org/what-is-an-operating-system/) image ([**AMI**](https://www.geeksforgeeks.org/what-is-amazon-machine-image-ami/)) as **Ubuntu.** You can also select another images. This OS image will give you the ability to interact with server.

![Defining the Instance](https://media.geeksforgeeks.org/wp-content/uploads/20240224211958/4.png align="left")

**Step 6:** Select default **key-pair name** and check box of [**http/https**](https://www.geeksforgeeks.org/difference-between-http-and-https/)**.** This will allow us to test your application on Http/https protocol.

![Configuring Network settings](https://media.geeksforgeeks.org/wp-content/uploads/20240224211959/5.png align="left")

**Step 7: Launch instance** from bottom right corner. After that you will get status as **success**.

![Create Instance](https://media.geeksforgeeks.org/wp-content/uploads/20240224212000/6.png align="left")

**Step 8:** Goto your instances and check box according to your instance name. And from top menu select **connect.** This will connect your ubuntu with your instance.

![Connecting To EC2 Instance](https://media.geeksforgeeks.org/wp-content/uploads/20240224212001/7.png align="left")

**Step 9:** Keep setting as it is and connect. This will connect your os with server.

![Connecting EC2 Instance Console](https://media.geeksforgeeks.org/wp-content/uploads/20240224212002/8.png align="left")

**Step 10:** This will open ubuntu terminal. Clone your project github repository into server. Provide your python application containing github url.

> *git clone &lt;your\_github\_repository\_url&gt;*

![Clone repo](https://media.geeksforgeeks.org/wp-content/uploads/20240224212003/9.png align="left")

**Step 11:** Move to **downloaded git repo** directory using **cd** command.

> *cd &lt;folder\_path&gt;*

![Navigate to the downloaded repo](https://media.geeksforgeeks.org/wp-content/uploads/20240224212004/10.png align="left")

**Step 12:** Now update present packages in server using following command.

> *sudo apt update*

![Update packages](https://media.geeksforgeeks.org/wp-content/uploads/20240224214408/11.png align="left")

**Step 13:** Install [**pip**](https://www.geeksforgeeks.org/how-to-install-a-python-module/) using python3 in server to install your packages using following command and press yes for any prompt.

> *sudo apt install python3-pip*

![Install pip3](https://media.geeksforgeeks.org/wp-content/uploads/20240224214409/12.png align="left")

**Step 14:** Now install all the dependencies into your server using [**requirements.txt**](https://www.geeksforgeeks.org/how-to-create-requirements-txt-file-in-python/)**.** If not present in your project create it.

> *pip3 install -r requirements.txt*

![Installing from Requirements.txt file](https://media.geeksforgeeks.org/wp-content/uploads/20240224214411/13.png align="left")

**Step 15:** Now run your application. Running your applications depends on what tech stack is used to make the application. In my case its FastAPI so I'll just directly run main.py.

Also copy [**public IP**](https://www.geeksforgeeks.org/what-is-public-ip-address/) from below and **port number** (for me 8000) . At this IP your app will be hosted.

![Run application](https://media.geeksforgeeks.org/wp-content/uploads/20240224214413/14.png align="left")

**Step 16:** Open new tab and enter your **IP** with **port number** separated with **colon (:)**.

![Accessing Deployed Application](https://media.geeksforgeeks.org/wp-content/uploads/20240224214414/15.png align="left")
