Open In App

How To Deploy Python Application In AWS?

In this article, we will explore how one as a Python developer can deploy 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?

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

Step 1: Log in with AWS Account with your credentials and Navigate to AWS Management Console.



Step 2: After signing in you will land on the AWS Management Console page and search for EC2 as shown below.



Step 3: This will land you on Amazon EC2 dashboard from there select instances from left menu.

Step 4: From top right, select Launch instances this will allow us to make EC2 instance (server). This server will contain all the necessary files which you need to deploy your application.

Step 5: Give name to your server and select OS image (AMI) as Ubuntu. You can also select another images. This OS image will give you the ability to interact with server.

Step 6: Select default key-pair name and check box of http/https. This will allow us to test your application on Http/https protocol.

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

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.

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

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

git clone <your_github_repository_url>

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

cd <folder_path>

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

sudo apt update

Step 13: Install pip using python3 in server to install your packages using following command and press yes for any prompt.

sudo apt install python3-pip

Step 14: Now install all the dependencies into your server using requirements.txt. If not present in your project create it.

pip3 install -r requirements.txt

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 from below and port number (for me 8000) . At this IP your app will be hosted.

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

Conclusion

In this article, we deployed python application on AWS using EC2 service provided by AWS. We used github repo and clone our code in server, also installed required packages and then run the application from which your application will be live in IP provided by AWS.

Python Deployment In AWS – FAQ’s

Can I Deploy A Python Application On AWS Lambda?

Yes, AWS Lambda supports Python. You can create a Lambda function, upload your Python code as a ZIP file, and configure triggers to execute your code in response to events.

How Can I Manage Environment Variables In My Python Application Deployed On AWS?

AWS provides services like AWS Systems Manager Parameter Store or AWS Secrets Manager to securely manage and retrieve environment variables.

Can I Deploy A Dockerzied Python Application On AWS?

Yes, using Amazon ECS (Elastic Container Service), AWS Fargate, or even running on EC2 instances with Docker installed you can deployed it.

How Can I Monitor The Performance Of My Python Application On AWS?

AWS offers services like Amazon CloudWatch for monitoring resources and application logs.


Article Tags :