Step-by-Step tutorial to deploy your Flask app to EC2 AWS Ubuntu 20.04 with Apache, WSGI, and Python 3

Why this tutorial?

Python 2 is now deprecated as of January 1st, 2020 so it’s time to move on to Python 3, and to make this transition easier is ideal to move from Ubuntu Server 16.04 instances, which are still running Python 2 by default to a newer version Ubuntu 20.04.

In this article, I will walk you through deploying your Flask app to an AWS EC2 environment on top of Ubuntu 20.04, Apache 2, wsgi, Python3, and MySQL step by step.

Prerequisites

  • AWS Account
  • Ubuntu 20.04 EC2 Instance
  • Shell Access
  • Comfortable with the command line/terminal

Architecting Flask Applications

Flask is advertised as a simple, lightweight framework to get you started quickly with Python web development. While that’s true, I find there isn’t enough guidance on how to structure projects properly. Here is a list of some commonly used patterns to better help explain what options are available in different scenarios.

Single Module

A single file that you typically come across when looking for Flask examples, often an app.py. This is good enough for quick projects where only a few routes are needed and you have less than a few hundred lines of code.

app.py
config.py
requirements.txt …


This is a quick introduction to Flask to get you started.

Minimal Requirements

- Mac OS
- Python 3
- Comfortable with the Terminal
- Code Editor — VS Code, Atom, etc

Python Version

Please use Python 3, as of this article Python 2.7 is officially deprecated.

Virtual Environments

Python 3 comes bundled with the venv module to create virtual environments. Virtual environments isolate your project’s dependencies and prevent version and library conflicts.

Create a project folder and a venv folder within in your machine’s user root directory. Launch the terminal and run the following commands.

$ cd
$ mkdir www
$ cd www
$ mkdir quickstart
$ cd quickstart
$ python3 -m venv quickstartvenv…

A guide to getting you sending emails quickly with Django

In this tutorial, you’ll learn how to configure a Django application to send emails using SendGrid’s email service and AWS Route 53. SendGrid offers a free plan which gives you 100 emails per day and it is enough to get you started.

To follow this tutorial you need the following items:

  • A SendGrid account
  • A registered domain
  • Configured Route 53 Host Zones
  • AWS account

Set Up A Domain on SendGrid

Log in to your SendGrid account and before anything create an API key. Click on the left sidebar, select Settings, then API Keys. Finally, click on Create API Key. In the pop-up window choose Restricted Access


Quick guide to patch React Native without upgrading

Photo by Silas Baisch on Unsplash

Today I decided to finally upgrade Xcode to version 12.0.1 which means the simulators were also upgraded to iOS version 14. The project I’m currently working on is on React Native version 0.61.5. I usually put off updating Xcode for a few weeks or until I have the spare time to deal with the side effects of this update.

The latest one is rather dramatic and prevents the Image component from displaying any images on iOS 14. Here is the related issue on Github and a screenshot for reference.


Learn to use Hooks and AsyncStorage with React Native

cat in a box

It’s a fairly common practice to persist user data between sessions in most mobile apps and to get this done with React Native is as simple as using AsyncStorage. This will allow you to keep changes, or updates to any components even if the app is restarted, refreshed or closed.

Take this counter for example, if you increment or decrement the count and restart the app, the count will reset back to zero.

import React, { useContext, createContext, useState } from 'react';
import { View, Button, StyleSheet, Text } from 'react-native';
const CounterContext = createContext(0);const useCounter = () =>…


React Native Android Build Errors — Quick Read

Photo by Sarah Kilian on Unsplash

If you keep seeing this error multiple times Daemon will be stopped at the end of the build after running out of JVM memory followed by Expiring Daemon because JVM heap space is exhausted it means you need to increase your JVM Heap memory. This error only was happening when trying to build an APK for React Native Android.

$ ./gradlew assembleRelease

And this is the dreaded output:


Photo by Diomari Madulara on Unsplash

Today I want to go over how you can become a Software Developer in the year 2020. We all know this has been a challenging year for a lot of us and you have to make sure to stand out from others. This plan will help you do that.

Here is the 10 step plan.

  1. Master the fundamentals.
    Regardless of your language of choice be JavaScript, Python, Go you should know the following
    - Variables
    - Conditionals
    - For Loops
    - While Loops
    - Object-Oriented Programming
    - Recursion
    You can cover all this and more in the free Galvanize Software Engineering Prep course


Become a better Software Engineer

Photo by Bench Accounting on Unsplash

In this article, I’ll go over some best practices of software engineering you can use today to be a better software engineer. Adopting these techniques will may you a better developer and prepare you to write production-level code. These techniques will make your code more readable and maintainable.

  • Write clean and modular code
  • Write efficient code
  • Refactor your code
  • Add meaningful documentation
  • Use version control

Write Clean and Modular Code

What is clean and modular code? It is a production-level code that meets the following criteria.

  • PRODUCTION CODE: software running on production servers to handle live users and data for the intended audience. This is…


Amazon EC2 Ubuntu

Photo by Curology on Unsplash

Just yesterday I was greeted with something that surprised me and was completely unexpected. I connected to one of my remote servers on AWS to submit some changes I made to a PDF report generator service running on EC2. As soon as I tried to pull my changes from Github I was greeted with

[log_config:warn] [pid 10720:tid 140282565658368] (28)No space left on device: 
  • First, check how much space…

jQN

I'm a Full-Stack Software Engineer who believes in the power of technology to change and improve lives. Connect with me on https://twitter.com/IamJQN

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store