I recently completed the Insight Data Science program, which involved the creation of a data science project from ideation through deployment (if interested, you can see my Insight project here). For deployment, a Flask webapp was created, and Amazon Web Services (AWS) was used to host it. I found that getting this all set up was one of the hardest things for fellows to accomplish, and recognized a few areas in which it could be improved.

The instructions below are an attempt to improve the instructions for getting a Flask webapp up and running on AWS. While I assume no prior knowledge of Flask, I do no go into any Flask basics here, but that may be a blog post for the future. I will try to go slowly through the steps, and offer plentiful code examples and screenshots. This guide will hopefully serve as a better reference for future Insight sessions.

Creating an AWS Instance

First, we must create an AWS virtual machine to copy our files to, and serve our website. To get started, head to aws.amazon.com and click the sign up button in the top right. Then, follow the steps to either sign into your existing Amazon.com account, or create a new one.

Unfortunately, I already went through the signup process, so I could not recreate some of the screens. I know you will have to enter your credit card information, but don't worry, we will only be using the free AWS tier, so you will not be charged. I believe AWS will also ask you what region you want your servers to be in. For convenience, select one of the western US options (I chose Oregon).

After completing signup, you will be presented with the AWS console screen, with all the products AWS has to offer. What we want to select is EC2, or Elastic Compute Cloud, the first option in the top left.

After selecting EC2, you will be presented with the EC2 console screen, which can also be overwhelming with the number of options to choose from. To get started, select the "Instances" tab on the left sidebar (under the Instances subheader), which will take you to the following screen:

I already have an instance created for my project, but the list you will see will be empty. Press the blue "Launch Instance" button to set up a new virtual machine for your project. You will immediately be asked to select an operating system, and you should select the "Ubuntu Server" option. As of this writing, the current version is 14.04, but these instructions should still work on future versions.

Next, you will select what type of instance you wish to create. For the free tier, there is only 1 option available, but there are many beefier virtual machines you could create if you wish to pay for the performance.

Continue through the setup, just clicking the blue continue buttons, until you reach the review step. At this stage, AWS will ask you to create a "key pair," that you will use to SSH into your instance.

Give it any name you wish ("aws" might be a good name), and click the "Download Key Pair" button. This will download a text file which contains the SSH key necessary to access the instance. Make sure to back this key file up! If you ever lose your key file, you will not be able to enter your instance. Your data will be recoverable, but it will be hassle, and should be avoided at all costs.

Once the key is downloaded, click the "Launch Instances" button, which should now be available.

Setting Up SSH

Before we worry about setting our files up on the instance, we should make sure we have easy access to log into the machine.

First, we need to determine where our virtual machine is. To find your instance's IP address, click back to the "Instances" tab, and select your instance. In the bottom right will list the IP address of the machine:

We can now use this IP address to log in via SSH. Normally, the login requires a lengthy SSH command: