A full, detailed guide on free hosting of a web app with SSL and database. Tips, tricks, troubleshooting and automation.
Kath Mitrich
Founder of SignalKite
A software developer with 18+ years of experience.
I love to create things.
Photo by Austin Distel on Unsplash
Why AWS
Amazon Web Service is a powerful platform that allows doing a lot of things. Literally speaking, you can do everything beginning with simple things like hosting and ending with super-complex machine learning modeling. Moreover, most of their services have:
- free trials
- 12-month free tier
- forever free offers
The full list of services with their free options can be found here.
Unfortunately, there are flaws too:
- To use many services and get the most out of them you need to be proficient in the service’s topics
- many services have confusing UI/UX and a million options
- some of the options can easily turn a free service into a crazy-cost one.
So, this article is dedicated to hosting applications with AWS. When you start a new startup you don’t want to pay a lot for an app that you are not sure to be within a year. Then, why wouldn’t use AWS to host the app, connect to your domain name, and provide SSL, alongside with a relational database?
Why host an app on AWS Elastic Beanstalk?
- It has a great free tier valid for 12 months.
- It’s not as hard as running your app, say, on DigitalOcean
- You can easily attach your own domain name and SSL.
Some flaws
- Traditionally, the UI/UX is not simple and intuitive but this article should guide you through all the obstacles and show all the tricks.
- It may be suitable only for apps that can be easily run on Linux (like Node.js or Python/Flask). We tried to run a .Net app but didn’t find a way to install the additional libraries that we needed.
Don’t forget to check [the Amazon program for startups](https://aws.amazon.com/activate/founders/) for additional funding and discounts!
We provide some solutions for Windows OS, please check the reference for other operating systems.
As a sample application, we will create an app written in Python (Flask).
Before we start, let’s define the list of tasks we would like to accomplish:
- Create an application (in terms of AWS) and deploy it
- Attach our own domain name and provide SSL
- Create the database and connect to it (we will work with PostgreSQL)
Prerequisites
You need the following tools and programs to be installed:
- IDE. We use MS VS Code
- Python. At the moment, it’s the version 3.8 but you can download a fresher version
- AWS CLI
- AWS EB CLI.
Create and deploy an app on AWS Elastic Beanstalk (EB)
Install and run your app locally
1. Create a folder and add the code there. The very minimal application in Flask may have as few as just 5 lines of code. You can copy this code into the application.py file and put it into a root folder.
2. Create a virtual environment If you don’t know what is a Python virtual environment you can read this nice guide.
Basically in your root folder you run the following command:
python -m venv venv
This is a command for Windows, for other OS it may look like this:
python3 -m venv venv
3. Select an interpreter In your VS Code, click View -> Command Palette -> Python: Select Interpreter and then enter into the prompt field:
.venvScriptspython.exe
4. Activate the virtual environment In your VS Code terminal, run the command to activate the virtual environment.
For Windows, run:
venvScriptsactivate.bat
For Mac/Linux, run:
source venv/bin/activate
5. Install the Python packages To run the Flask app, we need to install Flask itself. To do it, run the following command:
pip install flask
Usually, the Python package manager PIP installs automatically but if it didn’t happen please refer to the official documentation https://pip.pypa.io/en/stable/installation/.
6. Run your app To make sure the app works normally, run it:
flask run
In the case of some issues, please refer to the Flask Quick Start: https://flask.palletsprojects.com/en/1.1.x/quickstart/.
Set up the Amazon account
1. Create an account First, go to the AWS console and create a new account. You will need to verify your email, enter a credit card (even if you will only free tier), and verify your phone number.
2. Sign in to the AWS console Now you can sign in. Please note, that verification of your new account may take some time, up to several hours. It looks like you can sign in but can’t do anything in the console.
3. Copy your credentials Inside the AWS console, click your username (in the top right corner), and select Security credentials.
Scroll a bit and click the Create access key button:
You will see the warning titled “Root user access keys are not recommended”, click the checkbox and then the Create access key button.
In the next window copy both the access id and secret key. You also can download the keys in a file.
4. AWS EB Configuring In your IDE terminal run the command (if you have or will have multiple applications, please jump to p.5):
eb init
The command starts the configuring process and will ask you for credentials. It also will ask other questions like region (you need to remember the region because the application will be deployed exactly in the given region and will be visible in others).
If you don’t want to create SSH now, you can omit this step. (More details can be found here).
5. AWS EB Configuring for multiple apps If you have or plan to have multiple applications, you can try another approach. Open the C:Usersusername.awsconfig
or ~/.aws/config file (depending on your operating system) and add the following text:
[profile profile-app-1]
aws_access_key_id = XXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXX
[profile profile-app-2]
aws_access_key_id = XXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXX
The profile name is arbitrary (but should not contain spaces).
Then, when you configure EB, just use one of the profile names:
eb init --profile profile-app-2
6. Create an environment In terms of AWS, here is the hierarchy Application -> environment. So, the second step is to create an environment. Run the command: