Welcome to Day 12 of our DevOps Diary! Today, we'll take a hands-on approach to deploy your Django project from GitHub to AWS (Amazon Web Services). By the end of this day, you'll have your app up and running on an AWS instance.
Before we begin, make sure you have the following prerequisites in place:
- An AWS account with access to AWS services.
- Your Django project hosted on GitHub.
Let's break down the deployment process into actionable steps:
-
Log in to your AWS Management Console.
-
Navigate to the EC2 service and launch a new EC2 instance. Choose an Amazon Machine Image (AMI) based on your project requirements. A Linux-based AMI is a common choice.
-
Configure the instance details, including instance type, network settings, and storage.
-
Create or select a key pair for SSH access to your instance.
-
Review and launch the instance.
-
Use the key pair you created in the previous step to SSH into your EC2 instance:
ssh -i /path/to/your/keypair.pem ec2-user@your-instance-ip
-
Update the package manager and install the required dependencies for your Django project. This may include Python, virtualenv, and database drivers.
-
Clone your Django project from GitHub to the EC2 instance:
git clone https://github.com/your-username/your-django-project.git
-
Create a virtual environment and install project dependencies:
cd your-django-project python -m venv venv source venv/bin/activate pip install -r requirements.txt
-
Update your Django project settings to configure the database, static files, and other project-specific settings to work in the AWS environment.
-
Create a production-ready database, if needed, and apply migrations.
-
Install and configure Gunicorn as your application server. Create a Gunicorn service to run your Django app.
-
Install and configure Nginx as a reverse proxy to route HTTP requests to your Gunicorn server.
-
Secure your EC2 instance by updating the firewall rules (Security Group) to allow only necessary incoming traffic (e.g., HTTP, HTTPS, SSH).
-
Set up SSL/TLS certificates using AWS Certificate Manager or Let's Encrypt for secure HTTPS access.
-
Ensure your domain name is correctly configured to point to your AWS instance's public IP address.
-
Update the Nginx configuration to serve your Django app on your domain.
-
Restart Nginx and Gunicorn services to apply changes:
sudo systemctl restart nginx sudo systemctl restart gunicorn
-
Access your Django app in a web browser using your domain name.
-
Implement monitoring and logging solutions (e.g., AWS CloudWatch) to keep an eye on your app's health and performance.
-
Regularly update and maintain your AWS resources, Django project, and dependencies.
Congratulations! You've successfully deployed your Django project to AWS and exposed it to the internet. This marks the end of Day 12 of our DevOps Diary. Remember to regularly update and maintain your AWS resources and Django app to ensure they run smoothly.
Stay tuned for more DevOps adventures in the coming days!