Reader small image

You're reading from  Django in Production

Product typeBook
Published inApr 2024
Reading LevelIntermediate
PublisherPackt
ISBN-139781804610480
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Arghya Saha
Arghya Saha
author image
Arghya Saha

Arghya (argo) Saha, is a software developer with 8+ years of experience and has been working with Django since 2015. Apart from Django, he is proficient in JavaScript, ReactJS, Node.js, Postgres, AWS, and several other technologies. He has worked with multiple start-ups, such as Postman and HealthifyMe, among others, to build applications at scale. He currently works at Abnormal Security as a senior Site Reliability Engineer to explore his passion in the infrastructure domain. In his spare time, he writes tech blogs. He is also an adventurous person who has done multiple Himalayan treks and is an endurance athlete with multiple marathons and triathlons under his belt.
Read more about Arghya Saha

Right arrow

Deploying Django in AWS

In Chapter 12, we learned how to work with version control and use CI pipelines to run test cases and verify our code changes efficiently. In this chapter, we will take the next step toward our development cycle: learning how to deploy our Django application in production. While most books only cover application code development, we are going to take a step further and make sure we learn how to deploy our code on production. We are going to use Amazon Web Services (AWS) as a platform to deploy our Django code. There are several other cloud providers available, such as Azure, Google Cloud Platform (GCP), and Digital Ocean, but out of all the major cloud providers, AWS has one-third of the market share. This is why we will learn how to use AWS to host our Django application.

Important note

AWS is a vast topic and is a book in itself. We shall not look at how AWS works in depth; rather, our primary focus will be to learn how we can deploy our Django application...

Technical requirements

In this chapter, we shall work with AWS, primarily with Beanstalk, Relational Database Service (RDS), and ElastiCache, so we expect you to have some background in AWS. AWS provides free credits for 1 year that would be sufficient to follow all the steps mentioned in this chapter. You should also have access to a credit card so that you can create an account in AWS as you will need to enter your credit card details.

Please note that the examples used in this chapter fall within the free tier, so you will not be charged if you follow the instructions mentioned in this book.

If you are not familiar with AWS, it is recommended that you read the book AWS for System Administrators, by Prashant Lakhera, Packt Publishing, before proceeding with this chapter since we expect you to have some experience with cloud services.

There is another book called AWS Certified Developer – Associate Guide, by Vipul Tankariya and Bhavin Parman, Packt Publishing, that...

Learning the basics of AWS

AWS is a cloud service that lets us run our web applications on the cloud. AWS has numerous services that can be used to run our applications on the web and scale them as traffic grows. In this section, we will cover the basics of all the AWS services that we will be using to deploy our Django application to production.

Creating an account in AWS

First, we must create a new account with AWS. Here are the simple steps we can follow to create an account with AWS:

  1. Go to https://aws.amazon.com and go to the Sign up page.
  2. Fill out the form, as shown in Figure 13.1:
Figure 13.1: AWS sign up page

Figure 13.1: AWS sign up page

  1. Go to your mailbox to get the six-digit OTP from AWS to enter on the next screen.
  2. Fill in all the fields of the signup form regarding contact information and business information, as shown in Figure 13.2:

Figure 13.2: AWS sign up contact information

Figure 13.2: AWS sign up contact information

  1. Next, we have the...

Integrating AWS Elastic Beanstalk to deploy Django

In this section, we’ll learn how to use AWS Elastic Beanstalk to deploy Django applications. Let’s look at a basic Django example to help exemplify this.

Integrating Beanstalk with a basic Django app

First, follow the guide mentioned in Chapter 1 to create a Django application, followed by the guide mentioned in Chapter 11 to dockerize the Django application. Also, follow the instructions mentioned in https://github.com/PacktPublishing/Django-in-Production/tree/main/Chapter13#integrating-beanstalk-with-basic-django-app.

Before starting the Elastic Beanstalk integration, please ensure that the Django project is working by running docker compose up. We can access the Django admin page by going to http://127.0.0.1/admin:

docker compose up -–build

Now that our local setup is running the Django application using Docker, let’s focus on creating a new Beanstalk environment:

  1. Install the Elastic...

Following the best practices for the AWS infrastructure

In this section, we’ll learn about the best practices that should be followed while working with AWS services. AWS has a good architecture framework that AWS recommends organizations follow. For more details, check out https://aws.amazon.com/architecture/well-architected/.

The AWS Well-Architected Framework is extensive and might need additional effort to reach the state of. We won’t dive too deep into the AWS Well-Architected Framework, instead just listing the best practices that can help developers configure their AWS services better and make sure there are no loopholes in the system. We’ll start by looking into the best practices for RDS.

Best practices for RDS

In this section, we’ll discuss all the best practices for RDS that we should follow to run RDS in production:

  • Enable Cluster Delete protection: Enabling this flag in production is a must so that we do not accidentally delete...

Summary

In this chapter, we learned about different AWS components that we need to use to deploy our Django application to production. We used AWS Elastic Beanstalk to configure and deploy our Django application in production. We also used AWS RDS and ElastiCache for database and cache purposes in our Django application. AWS ensures we can scale our application infrastructure easily.

AWS Elastic Beanstalk is a managed platform service that can orchestrate applications by helping us deploy and scale them. AWS encapsulates all the important configurations and links between AWS services that are needed to deploy and run our application at scale.

Running a stable and performant application is important. In the next chapter, we’ll learn how we can continuously monitor our Django application running in production using tools such as New Relic, Rollbar, and others.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Django in Production
Published in: Apr 2024Publisher: PacktISBN-13: 9781804610480
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Arghya Saha

Arghya (argo) Saha, is a software developer with 8+ years of experience and has been working with Django since 2015. Apart from Django, he is proficient in JavaScript, ReactJS, Node.js, Postgres, AWS, and several other technologies. He has worked with multiple start-ups, such as Postman and HealthifyMe, among others, to build applications at scale. He currently works at Abnormal Security as a senior Site Reliability Engineer to explore his passion in the infrastructure domain. In his spare time, he writes tech blogs. He is also an adventurous person who has done multiple Himalayan treks and is an endurance athlete with multiple marathons and triathlons under his belt.
Read more about Arghya Saha