Some thoughts on AWS and Django

By Thomas Dang on Aug. 27, 2018, 11:21 a.m.

Last month I made a first attempt to set up my blog website thomasbyte.com using Django and AWS Elastic Beanstalk. It took me two full days to successfully deploy my website for the first time, and I would like to share my thoughts on the overall experience as someone who is relatively new to web development.

Wiring it all up

My first starting point was reading the AWS Elastic Beanstalk docs on how to deploy a Django website here.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html

But the docs were not straight forward for me due to my lack of experience with AWS tools at the time. In search for a more structural approach, I proceeded to follow a tutorial published by this website.
https://realpython.com/deploying-a-django-app-and-postgresql-to-aws-elastic-beanstalk/

I had no major hurdles in that tutorial for about the first 80% of instructions, but I fell flat in terms of setting up the proper configurations for website deployment. Fortunately, I eventually found success by combining the instructions from both the RealPython tutorial and AWS docs. With this experience I have concluded that if you want to learn Django and AWS, I recommend carefully reading the two resources that I linked together.

Load Balancers

When it comes to the experience of AWS, there is a good amount of flexibility in configuring your website via PaaS. The benefit of Elastic Beanstalk is that it provides easy configurable tools to dynamically scale servers and utilize load balancers for traffic stability distribution. Here is a small snippet of what that looks like on the AWS console.
scaling.jpg

SSL

You can easily modify load balancers to include a SSL certificate that encrypts client-side connections. You can either import this SSL certificate from an external source or generate one using the AWS Certificate Manager. I opted to go with AWS, and by generating a certificate you must also include a CNAME record to the DNS configuration for your Domain.

Route 53

Fortunately, AWS has a great tool called Route 53. This service allows you to set up and manage a Domain Name System (DNS) without too much hassle. I created my domain name through Namecheap and wiring that domain with Route 53 is just a matter of linking record sets.

Infrastructure Configuration

Elastic Beanstalk comes in handy by providing an environment where you can deploy multiple versions of your web app. This allows you to have a test version while maintaining a production version in a relatively easy manner. Once you create a web app, you have the option to create a RDS database that is tied to that web app’s lifecycle through the configuration section.
database.jpg
This method is fine for testing purposes, but you want to avoid this approach for deploying production environments. If you ever decide to delete a production environment in the future, your RDS database is forced to be deleted as well. It is better to create an isolated RDS instance that is not tied to your web app lifecycle so that your infrastructure stays modular.

Environment Properties

One convenient feature with Elastic Beanstalk is that you can set up environment variables for your server through the AWS console. Environment variables are extremely important for production because they allow you to decouple sensitive information like API keys and database passwords. You do not want that information to be found in your source code. With Elastic Beanstalk, you can simply make environment variables as shown below.
environment_properties.jpg

Cost

When it comes to cost, you can stay on the AWS free tier for the first 12 months. Here is a breakdown of what the cost structure looks like under the AWS free tier.
https://aws.amazon.com/free/
There is also nice billing dashboard that helps you monitor and manage costs. You can even customize alerts to help warn you of rising costs.
budget.jpg

Concluding Thoughts

Overall, I see why AWS is great for enterprise purposes. What makes AWS so elegant is that you have all its services linked together in a streamlined ecosystem. I think this is great for someone who wants to learn all the moving parts of taking a web app from inception to production.

Now that I have my website set up, my next goal is to learn how to set up CloudFront as a Content Delivery Network. I am also very curious about AWS Lambda. I know that there is a buzz surrounding serverless hosting, so I might write a post on that topic once I figure out how it works. Stay tuned!

blog comments powered by Disqus