> ## Documentation Index
> Fetch the complete documentation index at: https://help.draftable.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API Self-hosted AWS EC2 deployment guide

> If you intend on using AWS EC2 to host your Draftable Self-hosted image, this guide provides a step by step process for this exact deployment. 

<Warning>
  **This documentation is for API Self-Hosted Version 2 (Legacy)**

  Version 2 is a legacy deployment model. All new customers **must** use Version 3, which features a modern multi-container architecture with improved security and performance.

  👉 [Get started with API Self-Hosted v3](/hc/en-us/articles/51133475373465-API-Self-Hosted-v3-Quick-Start-Guide)
</Warning>

## Prerequisites 

You will need to ensure you have the following ready before beginning this deployment.

1. You have logged into your AWS console with elevated privileges
2. You have selected the correct region in the AWS console where you are going to host your instance

## Deployment steps

The deployment steps are broken down into the following sections. 

* [User configuration:](#user-configuration) Account configuration for the AWS user that will interact with the instance configuration.
* [Launching a EC2 instance](#launching-a-ec2-instance): Process of the initial configuration for your EC2 instance.
* [Instance configuration](#instance-configuration): Adding the Draftable container to your instance, configuring the Self-hosted instance and restarting your container with Self-hosted configured.

### User configuration

<Steps>
  <Step>
    Navigate to your **IAM users.** We are going to create a new user by selecting the **add users** option. (**Note:** if editing an existing user account instead skip to step 5)

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-65.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=fc5950116bc44946c6d358382526f1f6" alt="" width="1254" height="550" data-path="images/draftable-api-self-hosted/image-65.png" />
    </Frame>
  </Step>

  <Step>
    Enter details for the new user, ensure that you have the following AWS credential parameters enabled: **Access Key** and **Password.** Then click **next**. 

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-66.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=d55fb3764c15572a358951887fd27e2c" alt="" width="1059" height="720" data-path="images/draftable-api-self-hosted/image-66.png" />
    </Frame>
  </Step>

  <Step>
    Now we include specific policies on the account. Ensure you include the *AdministratorAccess* and *IAMUserChangePassword* policies to the account. Then click **next**.

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-67.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=48940343d1043ec22232c3c50cfdb0dc" alt="" width="1065" height="875" data-path="images/draftable-api-self-hosted/image-67.png" />
    </Frame>
  </Step>

  <Step>
    Ignoring the **tags** step, go straight to the **review** page. Ensure that the two policies we added earlier are present. If all looks good, click **create user**.

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-68.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=f28c5ba85ae0de3996c77ed5e2c2ca41" alt="" width="1036" height="883" data-path="images/draftable-api-self-hosted/image-68.png" />
    </Frame>
  </Step>

  <Step>
    Open the user account again and go the **permissions** page. We to add an additional permission called *AmazonEC2ContainerRegistryFullAccess.* Add this policy and hit **next,** then **add permissions**.

    <Frame>
      <img src="https://mintcdn.com/draftable/XirHSA4IUskuCT0o/images/draftable-api-self-hosted/image68-1.png?fit=max&auto=format&n=XirHSA4IUskuCT0o&q=85&s=f5642a1418ca3b478361b5b01864ed2b" alt="" width="1248" height="237" data-path="images/draftable-api-self-hosted/image68-1.png" />
    </Frame>

    <br />

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-69.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=300bcded7f7e094deca0c94a0feed5a4" alt="" width="1296" height="340" data-path="images/draftable-api-self-hosted/image-69.png" />
    </Frame>
  </Step>
</Steps>

### Launching a EC2 instance

#### **Prerequisites** 

Ensure you have setup the following:

* Logged into the AWS console as the user created/edit in the user configuration section.
* Have the correct region selected before continuing with instance setup.

<Steps>
  <Step>
    Navigate to the **EC2 dashboard** and select the **Launch instance** option. 

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-70.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=f001b4b586c74ceff9ec5c885f9561c5" alt="" width="802" height="628" data-path="images/draftable-api-self-hosted/image-70.png" />
    </Frame>
  </Step>

  <Step>
    Draftable API Self-hosted runs on any Linux operating system which has both docker support and uses a Linux kernel. Provide a **name** for your instance and then select **Amazon Linux** as the AMI.

    <Note>
      You can deviate from the example below and choose a different Linux operating system, as long as it still supports the above requirements. 
    </Note>

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-71.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=5dccf5632a8c21ca38898e3fdbb3a7fc" alt="" width="802" height="798" data-path="images/draftable-api-self-hosted/image-71.png" />
    </Frame>
  </Step>

  <Step>
    Continue to configure the instance by selecting a **x64** architecture, and then selecting a instance type that is at least **t2.medium** or higher. Key pair should be the same one used as part as the login for the AWS user. 

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-72.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=a47b685f7c972596d23951e01f0a85e6" alt="" width="622" height="502" data-path="images/draftable-api-self-hosted/image-72.png" />
    </Frame>
  </Step>

  <Step>
    Configure the **network settings** as detailed below, create a new **firewall security group** and allow **SSH**, **HTTPS** and **HTTP** traffic from the internet. Depending on your use case you may want to change some of these parameters at a later time, but for the configuration process please allow all during the setup process. 

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-73.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=82f7ca40cb40f1c5ab3bd5cbfbe4adb0" alt="" width="777" height="696" data-path="images/draftable-api-self-hosted/image-73.png" />
    </Frame>

    Following this configuration, you should be left with a following summary of settings. Ensure they are correct to the settings provided earlier. 

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-74.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=6372b7b36501d5cfcdc6910f39bb5445" alt="" width="369" height="720" data-path="images/draftable-api-self-hosted/image-74.png" />
    </Frame>
  </Step>

  <Step>
    Click **launch instance.** Your EC2 instance should now be running.
  </Step>
</Steps>

### Instance configuration 

#### **Prerequisites** 

Ensure you have setup the following:

* Logged into the AWS console as the user created/edit in the user configuration section.
* Are on the **instances** page before continuing.

<Steps>
  <Step>
    Select on your newly created instance and click on **connect to your instance.** Ensure the username s correct and then select **connect**.

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-75.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=8abe4912725f42e223c8d8a0073d96a1" alt="" width="827" height="600" data-path="images/draftable-api-self-hosted/image-75.png" />
    </Frame>
  </Step>

  <Step>
    In this instance terminal we will configure and add the latest Draftable Self-hosted image. First we need to add docker to the instance, which can be done with the command below:

    ```bash theme={null}
    sudo yum install -y docker
    ```

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-76.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=9593734a3359c54042f299422a83efe4" alt="" width="1050" height="259" data-path="images/draftable-api-self-hosted/image-76.png" />
    </Frame>
  </Step>

  <Step>
    Now we need to add docker-compose to the instance, use the commands below:

    ```bash theme={null}
    sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
    ```

    ```bash theme={null}
    sudo chmod +x /usr/local/bin/docker-compose
    ```

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-77.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=8414b0daadb6292672282bd3a4a509ee" alt="" width="1277" height="86" data-path="images/draftable-api-self-hosted/image-77.png" />
    </Frame>
  </Step>

  <Step>
    We can now verify that docker compose has installed correctly by using the command below:

    ```bash theme={null}
    docker-compose version
    ```

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-78.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=750f28d92d955ec4ffba616b78472603" alt="" width="1044" height="315" data-path="images/draftable-api-self-hosted/image-78.png" />
    </Frame>
  </Step>

  <Step>
    Now create the ***docker-compose.yml*** file, use the command below:

    ```bash theme={null}
    touch docker-compose.yml
    ```
  </Step>

  <Step>
    Now we need to edit the *docker-compose* file to add all the correct parameters for the instance. To start editing the file use the command below:

    ```bash theme={null}
    nano docker-compose.yml
    ```
  </Step>

  <Step>
    Now using this file editor, populate the YAML file with the correct configuration. For references on this topic see our [docker-compose guide](/hc/en-us/articles/6140153331993-Using-docker-compose-to-launch-instances) and [settings reference.](/hc/en-us/articles/6140653011865-Understanding-the-docker-compose-yml-file-and-parameters-guide) For this example we are using the most basic YAML configuration. 

    <Frame>
      <img src="https://mintcdn.com/draftable/YGM9Qz2FWPff3K0D/images/draftable-api-self-hosted/image-79.png?fit=max&auto=format&n=YGM9Qz2FWPff3K0D&q=85&s=05fb4c9415bfaf98fc46b83e3acae58a" alt="" width="780" height="387" data-path="images/draftable-api-self-hosted/image-79.png" />
    </Frame>
  </Step>

  <Step>
    Save and close the *docker-compose* file, and then start the docker daemon with the following command: 

    ```bash theme={null}
    sudo systemctl start docker
    ```
  </Step>

  <Step>
    Now start the instance using the command below: docker-compose up

    <Note>
      You may receive a permissions error regarding the instance trying to connect to the Docker Daemon. If so run this command to correct permissions:
    </Note>

    ```
    sudo chmod 666 /var/run/docker.sock
    ```
  </Step>

  <Step>
    Your instance should launch from here. You can go back to your **EC2 instances** list and extract a IP address to connect to your instance via the web browser to start configuration.

    <Frame>
      <img src="https://mintcdn.com/draftable/XirHSA4IUskuCT0o/images/draftable-api-self-hosted/image-80.png?fit=max&auto=format&n=XirHSA4IUskuCT0o&q=85&s=34e055ee983e8a6d673a82621daee8eb" alt="" width="1050" height="291" data-path="images/draftable-api-self-hosted/image-80.png" />
    </Frame>
  </Step>

  <Step>
    From here, please refer to our [first time configuration guide](/hc/en-us/articles/8424839618457-Draftable-Self-hosted-instance-first-time-configuration).

    <Frame>
      <img src="https://mintcdn.com/draftable/XirHSA4IUskuCT0o/images/draftable-api-self-hosted/image-81.png?fit=max&auto=format&n=XirHSA4IUskuCT0o&q=85&s=36abd3775522c25c38965e4d5e1d661e" alt="" width="1022" height="771" data-path="images/draftable-api-self-hosted/image-81.png" />
    </Frame>

    If you are having difficulty following this guide or getting Draftable Self-hosted to work on your AWS EC2, please get in contact with our support team at [support@draftable.com.](mailto:support@draftable.com)
  </Step>
</Steps>
