.. _install-on-aws:

Install on AWS
--------------

This section describes how to install the Driverless AI AMI from AWS.

**Watch the installation video** `here <https://www.youtube.com/watch?v=BQwUCeX2w7c&index=7&list=PLNtMya54qvOE9fs3ylzaR_McnoUsuMV7X>`__. Note that some of the images in this video may change between releases, but the installation steps remain the same. 

Environment
~~~~~~~~~~~

+----------------------------+---------------+----------+-----------------+
| Provider                   | Instance Type | Num GPUs | Suitable for    |
+============================+===============+==========+=================+
| AWS                        | p2.xlarge     | 1        | Experimentation |
|                            +---------------+----------+-----------------+
|                            | p2.8xlarge    | 8        | Serious use     |
|                            +---------------+----------+-----------------+
|                            | p2.16xlarge   | 16       | Serious use     |
|                            +---------------+----------+-----------------+
|                            | p3.2xlarge    | 1        | Experimentation |
|                            +---------------+----------+-----------------+
|                            | p3.8xlarge    | 4        | Serious use     |
|                            +---------------+----------+-----------------+
|                            | p3.16xlarge   | 8        | Serious use     |
|                            +---------------+----------+-----------------+
|                            | g3.4xlarge    | 1        | Experimentation |
|                            +---------------+----------+-----------------+
|                            | g3.8xlarge    | 2        | Experimentation |
|                            +---------------+----------+-----------------+
|                            | g3.16xlarge   | 4        | Serious use     |
+----------------------------+---------------+----------+-----------------+


Installing the EC2 Instance
~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. Log in to your AWS account at https://aws.amazon.com.

2. In the upper right corner of the Amazon Web Services page, make sure that the location drop-down is US East (N Virginia).

 .. image:: ../images/ami_location_dropdown.png
    :align: center


3. Select the EC2 option under the Compute section to open the EC2 Dashboard. 

 .. image:: ../images/ami_select_ec2.png
    :align: center

4. Click the **Launch Instance** button under the Create Instance section. 

 .. image:: ../images/ami_launch_instance_button.png
    :align: center

5. Under Community AMIs, search for **h2oai**, and then select the version that you want to launch. 

 .. image:: ../images/ami_select_h2oai_ami.png
    :align: center

6. On the Choose an Instance Type page, select **GPU compute** in the **Filter by** dropdown. This will ensure that your Driverless AI instance will run on GPUs. Select a GPU compute instance from the available options. (We recommend at least 32 vCPUs.) Click the **Next: Configure Instance Details** button. 

 .. image:: ../images/ami_choose_instance_type.png
    :align: center

7. Specify the Instance Details that you want to configure. Create a VPC or use an existing one, and ensure that "Auto-Assign Public IP" is enabled and associated to your subnet. Click **Next: Add Storage**.

 .. image:: ../images/ami_configure_instance_details.png
    :align: center

8. Specify the Storage Device settings. Note again that Driverless AI requires 10 GB to run and will stop working of less than 10 GB is available. The machine should have a minimum of 30 GB of disk space. Click **Next: Add Tags**.

 .. image:: ../images/ami_add_storage.png
    :align: center

9. If desired, add unique Tag name to identify your instance. Click **Next: Configure Security Group**.

10. Add the following security rules to enable SSH access to Driverless AI, then click **Review and Launch**.

+-----------------+-----------+---------------+--------------------+-----------------------------+
| Type            | Protocol  | Port Range    | Source             | Description                 |
+=================+===========+===============+====================+=============================+
| SSH             | TCP       | 22            | Anywhere 0.0.0.0/0 |                             |
+-----------------+-----------+---------------+--------------------+-----------------------------+
| Custom TCP Rule | TCP       | 12345         | Anywhere 0.0.0.0/0 | Launch DAI                  |
+-----------------+-----------+---------------+--------------------+-----------------------------+

 .. image:: ../images/ami_add_security_rules.png
    :align: center

11. Review the configuration, and then click **Launch**.

12. A popup will appear prompting you to select a key pair. This is required in order to SSH into the instance. You can select your existing key pair or create a new one. Be sure to accept the acknowledgement, then click **Launch Instances** to start the new instance.

 .. image:: ../images/ami_select_key_pair.png
    :align: center

13. Upon successful completion, a message will display informing you that your instance is launching. Click the **View Instances** button to see information about the instance including the IP address. The **Connect** button on this page provides information on how to SSH into your instance.

14. Open a Terminal window and SSH into the IP address of the AWS instance. Replace the DNS name below with your instance DNS. 

 :: 

   ssh -i "mykeypair.pem" ubuntu@ec2-34-230-6-230.compute-1.amazonaws.com 

15. If you selected a GPU-compute instance, then enable persistence of the GPU. Note that this only needs to be run once. Refer to the following for more information: http://docs.nvidia.com/deploy/driver-persistence/index.html.

  :: 

    sudo nvidia-persistenced --user <USER>
    sudo nvidia-smi -pm 1

16. At this point, you can copy data into the data directory on the host machine using ``scp``. (Note that the data folder already exists.) For example:

 ::

  scp <data_file>.csv ubuntu@ec2-34-230-6-230.compute-1.amazonaws.com:/home//data

 The data will be visible inside the Docker container.

17. Connect to Driverless AI with your browser:

 ::

    http://Your-Driverless-AI-Host-Machine:12345

Stopping the EC2 Instance
~~~~~~~~~~~~~~~~~~~~~~~~~

The EC2 instance will continue to run even when you close the aws.amazon.com portal. To stop the instance: 

1. On the EC2 Dashboard, click the **Running Instances** link under the Resources section.
2. Select the instance that you want to stop.
3. In the **Actions** drop down menu, select **Instance State > Stop**. 
4. A confirmation page will display. Click **Yes, Stop** to stop the instance. 

.. include:: upgrade-aws-image.rst

.. include:: aws-role-based-authentication.rst

