# Remote Development With AWS EC2

This guide will walk the reader through setting up a remote instance in AWS EC2 and connecting with that instance with the VSCode Remote - SSH extension. This allows users who do not have a compatible local environment to do channel development and can be a good way to ensure your channel will run correctly after being deployed to the platform.

* [Configuring an EC2 Instance](#configuring-an-ec2-instance)
  * [Select an AMI](#select-an-ami)
  * [Launch the Instance](#launch-the-instance)
  * [Restrict Identity File Permissions](#launch-the-instance-1)
* [Connect to the Instance in VSCode](#connect-to-the-instance-in-vscode)

## Configuring an EC2 Instance <a href="#configuring-an-ec2-instance" id="configuring-an-ec2-instance"></a>

Selecting the right EC2 image, instance, disk space, etc can be a point of confusion. To start configuring a new instance for channel development, sign in to your AWS account, set the region you want to use for the compute, and go to the EC2 dashboard.

#### Select an AMI <a href="#select-an-ami" id="select-an-ami"></a>

The AMI Catalog has several pre-configured instances that will work for channel development. The instance operating system needs to be Linux-based and will need NVIDIA and Docker. In this example, we will use the Ubuntu Deep Learning Base AMI. To find this AMI in the EC2 dashboard, look under Images and navigate the AMI Catalog then search for “nvidia”. After selecting the AMI, click the _Launch Instance with AMI_ button at the top to move on in the setup wizard.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2FwxvBrE7Z5YCwFexfifpN%2Fimage.png?alt=media&#x26;token=5c1a4150-9b00-4e9e-bf7c-a4313b0c6cd5" alt=""><figcaption></figcaption></figure>

In the “Launch an instance” dialogue, give the instance a name, such as “Channel Development”, and select a an instance type. We recommend selecting an instance that has at least one GPU, for example, an instance from the p or g family.

The majority of channels launched on the Rendered.ai platform use the AWS _g4dn.2xlarge_ instance type.&#x20;

Next a Key Pair is added so you can connect to the instance locally. If you have not set up a Key Pair in AWS, follow the dialog using all the default options. Download the .pem file and do not loose it! This is your key to accessing instance once it's running.

Finally, you might want to add extra disk space for storing generated images and videos. We recommend adding 100 GB of general purpose storage. AWS has a procedure to move your AMI to an instance with more storage later, but it's easier to add it here.

Now you can launch the instance. The default values for the remaining parameters are appropriate for channel development (generic security group, allow SSH traffic).

#### Launch the Instance <a href="#launch-the-instance" id="launch-the-instance"></a>

After completing the wizard, the instance will begin the launch process. This can take some time depending on the instance type and availability. You will need to wait until your instance is in the Running state with “2/2 checks passed” for the status check.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2FDOOoQEde8Nd2CtINu1MC%2F79d19753-e6dc-44c8-988c-6b5ed372999f.png?alt=media&#x26;token=33711ccf-61df-47c8-84aa-529b54ce339c" alt=""><figcaption><p>AWS Instances View</p></figcaption></figure>

Billing is calculated from when the instance starts running. Make sure to stop the instance when you are done!

Once the instance is in the “Running” state you can ssh to it using the Public IPv4 address and DNS.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2F2HNvSJaL4KhJiVfsaL27%2Fd2d83983-f959-41a5-8f13-daaf96dc4ba1.png?alt=media&#x26;token=edc362ae-9ea0-4b3d-b89c-705eecfe232b" alt=""><figcaption><p>Find the Instance Public DNS</p></figcaption></figure>

In the above screenshot, the public DNS is circled. Copy this for the configuration of VSCode below. For information about more ways to connect to the instance, including from the command line, follow the Connect button.

#### Restrict the Permissions of your PEM file <a href="#launch-the-instance" id="launch-the-instance"></a>

It is required the local identity file not be readable by others. On Mac and Linux, the permissions can be set in a shell as follows:\
`chmod 400 <key name>.pem`

For Windows developers, we recommend installing Ubuntu in WSL, the Windows Subsystem for Linux.

* From PowerShell, run "wsl --install -d ubuntu"; you’ll have to create a username and password for the new OS.
* Find and save the \*.pem file from earlier into a directory that can be accessed by WSL Ubuntu.
* Update the permissions of the .pem file by rght clicking on it, selecting "Properties" and check "Read-only".  Next, under "Security" - "Advanced", select "Disable Inheritance" and for the users, "Remove All".  Click "Apply", and your group or user names should be empty. Go back to "Advanced" and add your windows user and apply.  Next, in the permissions give all permissions to your user.&#x20;

## Connect to the Instance in VSCode <a href="#connect-to-the-instance-in-vscode" id="connect-to-the-instance-in-vscode"></a>

Open VSCode and install “Remote - SSH” and “Remote - Containers” extensions. In the following screen shot, the extensions menu is active and the said extensions are found by searching for the keyword “remote”.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2F6MCnzfU6owwnVyTm7RI8%2F6e1cd476-fa34-4658-a779-9f95f55b5123.png?alt=media&#x26;token=74c71cff-0df6-4fc6-aadd-9e93ec0c298a" alt=""><figcaption><p>VSCode Extensions Can be Found in the Red Circled Button</p></figcaption></figure>

To connect to the AMI, update your ssh config file. This can be done right in VS Code by clicking the green box on the bottom left and then “Open SSH Configuration File…”.&#x20;

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2F4y4I9CEZ1eWggrv28HUW%2F82314733-2ad7-408f-afab-6a5d8c62281b.png?alt=media&#x26;token=f133e2df-56c2-4fee-afd1-4d3d8cfffe9d" alt=""><figcaption></figcaption></figure>

This file is in your home directory, _\~/.ssh/config_. On Windows, you need to restrict the permissions on the ssh config file as described above for the .pem file.

Add an entry to the ssh configuration file as follows:

```
Host <ami name>
    HostName <public DNS>
    IdentityFile <key location>/<key name>.pem
    User ec2-user
```

All the items that are surrounded by angle bracket need to be replaced.

* \<ami name> is the name of the host, e.g. ‘anadevami’. This can be whatever reminds you of the entry when connecting
* \<public DNS> is the URL from the AWS dashboard above, it takes the form '`ec2-xx-xx-xx-xx.us-xxx-x.compute.amazonaws.com`'
* \<key name> is the name you gave the key pair and \<key location> is where the .pem file is stored. This might be in Downloads and is safely stored by moving it to the .aws directory in your home directory.

Now you can connect to the instance by using the “Connect to Host…” command in VSCode.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2F6ZmjysSuurA92JQG4ltW%2F41b7a3a3-8d8f-4392-97de-b1c897cccd82.png?alt=media&#x26;token=00b87ff8-2b25-4862-9e47-769d9a332b61" alt=""><figcaption><p>Connect to the AMI</p></figcaption></figure>

Clicking “Connect to Host…” will then list all the entries in your ssh config file. Select the one you just created.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2FRCrMa9tb9D8knJ4i2wKD%2F5c83359e-e7ba-4252-8db6-e858564ef755.png?alt=media&#x26;token=bd6bb70d-3476-43e7-b916-56971ac45f97" alt=""><figcaption><p>Choose the New SSH Config</p></figcaption></figure>

Watch the lower left green icon to verify VSCode is connected to the host. If you have trouble connecting, the logs can be found in VSCode to run down any issues.

Now you can clone a channel repository and begin development as described here:&#x20;

{% content-ref url="../an-example-channel-toybox/run-and-deploy-the-toybox-channel" %}
[run-and-deploy-the-toybox-channel](../an-example-channel-toybox/run-and-deploy-the-toybox-channel)
{% endcontent-ref %}
