AI_DL_Assignment / 29. BONUS - Create a Computer Vision API & Web App Using Flask and AWS /5. Setting Up Your AWS EC2 Instance & Installing Keras, TensorFlow, OpenCV & Flask.html
Prince-1's picture
Add files using upload-large-folder tool
17e2002 verified
<h4><strong>Launching Your E2C Instance</strong></h4><p><br></p><p><strong>Step 1: </strong>Your landing page upon logging in should be the AWS Management Console (see below). Click on the area highlighted in yellow that says "<strong>Launch a virtual Machine" with EC2. </strong></p><p><strong>What is EC2?</strong> Amazon Elastic Compute Cloud <strong>(Amazon EC2</strong>) provides scalable computing capacity in the Amazon Web Services (AWS) cloud. Using Amazon EC2 eliminates your need to invest in hardware up front, so you can develop and deploy applications faster.</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-0aee9b0a53c5ff7d333b8dd78c366150.png">.</figure><p><strong>Step 2: </strong>As a Basic Plan (FREE) User, you're eligible to launch and use any of the "Free tier" AMIs. The one we'll be using in this project is the <strong>Ubuntu Server 18.04 LTS (HVM), SSD Volume Type. </strong>See image below, you'll have to scroll down a bit to find it amongst the many AMIs. We use this image as it's quite easy to get everything up and running.</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-4d7f42fec9fa73be91dd3f3a3220528e.JPG"></figure><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-d96a0fbdc7d781c023e2757b48448c94.png"></figure><p><strong>Step 3: </strong>Choosing an Instance Type - We already have chosen the type of OS we want to use (Ubuntu 18.04), now we have to choose a hardware configuration. We aren't given much of a choice due to our Free Tier limitations. The <strong>t2.micro </strong>will suffice for our application needs for now. Click<strong> Review and Launch</strong> (highlighted in yellow)</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-ed95c62d0d19c294264eaeb85edcccca.png"></figure><p><strong>Step 4: </strong>Reviewing and launching. No need to change anything here, the defaults are fine. Click <strong>Launch </strong>(highlighted in yellow)</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-0025d77e49af0f8a63c75d9e48eaaff7.png"></figure><p><strong>Step 5A:</strong> Creating a new Key Pair. If this is your first time you will need to create a new Key Pair. Click on the drop-down highlighted in yellow below. </p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-86bd4ffddae1ee4571d968a8f83eb03c.png"></figure><p><strong>Step 5B:</strong> GIve you key a name e.g. my_aws_key and Download Key Pair (please don't lose this file otherwise you won't be able to log in to your EC2 instance). </p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-abdb2db33153383c11e9b9b2ba8d3507.png"></figure><p><strong>Step 5C:</strong> Your Instance has been launched, it will take a few mins for AWS to create and have your instance up and running </p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-4cb08dac37637149ccea79e3ac7c5308.JPG"></figure><p><strong>Step 6A: </strong>Clicking View instances brings up the EC2 Dashboard. </p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_04-43-09-5ca178d2ec6fd40b8d12cb7cfb4be0aa.JPG"></figure><p><strong>Step 6B: </strong>To view the details of the individual instance you just launched, click on Instances under Instances on the left panel. </p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_04-42-05-97d85a5b7eddd3f6b1daa5f13e628bbb.JPG"></figure><p><strong>Step 7:</strong> Viewing your Instance public IP. Note your IP as you'll need it later when connecting to your instance.</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-7078b5ec1ac74f7cef875bcb375f4491.JPG"></figure><p><strong>Step 8:</strong> Assuming you're using Ubuntu on the VM (if not it's highly recommended as I find using Putty and SSH keys over windows to be sometimes problematic). Note Windows isn't always, so you're welcome to try using the guide here: <a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/tutorials-windows-launch-instance.html" rel="noopener noreferrer" target="_blank">https://docs.aws.amazon.com/codedeploy/latest/userguide/tutorials-windows-launch-instance.html</a>) </p><p>Mac instructions would be the same as the Ubuntu instructions.</p><p>Let's chmod your downloaded key to protect it from overwriting. If you've never used ssh on your VM, create a ./ssh folder in the home director. The following commands also assume your key is in the downloaded directory.</p><pre class="prettyprint linenums">mkdir ${HOME}/.ssh
cp ~/Downloads/my_aws_key.pem ~/.ssh
chmod 400 ~/.ssh/my_aws_key.pem
</pre><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-801b1770189ee4cf1c938303db5c8e1a.JPG"></figure><p><strong>Step 9: </strong>Connecting to your EC2 instance via Terminal, by running this:</p><pre class="prettyprint linenums">ssh -i ~/.ssh/my_aws_key.pem ubuntu@18.224.96.38</pre><p>You'll be prompted by the following, type yes and hit Enter.</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_04-55-08-2c5ae7fb992ca463892c46e286737ec1.JPG"></figure><p>You'll now be greeted by this! Congratulations, you've connected to your EC2 Instance successfully!</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-2dd7621c922e4b091bff0b7ad3946f5a.JPG"></figure><p><strong>Step 10:</strong> Installing the necessary packages by executing the following commands:</p><pre class="prettyprint linenums">sudo apt update
sudo apt install python3-pip
sudo pip3 install tensorflow
sudo pip3 install keras
sudo pip3 install flask</pre><p><strong>Note</strong>: As of April 2019, <code>sudo pip3 install opencv-python</code> appears to be broken, if importing cv2 fails, run <code>sudo apt install python3-opencv</code></p><pre class="prettyprint linenums">sudo pip3 install opencv-python
sudo apt install python3-opencv </pre><p>Screenshots of the TensorFlow install:</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-24960fe6ebff21df1e02c50823526ade.jpg"></figure><p>Screenshots of the Keras install:</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-403c9055c8dddcf04c44cff5c7a2ec17.jpg"></figure><p>Screenshots of the Flask install:</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_03-06-48-cf2ee18e183e6455ff9d01957dece8af.jpg"></figure><p>We've successfully installed all libraries needed for our API and Web App on our EC2 Instance!</p><p><strong>In the next chapters, we'll:</strong></p><ul><li><p>Setup Filezilla to transfer our code to your EC2</p></li><li><p>Setup our Security Group on AWS to allow TCP traffic.</p></li></ul>