# Setup via EC2 Instance

This guide will help understand how to install a PlayAI Node on EC2 instance. This guide is divided into 5 major steps, all parts are descriptive and have video and image content to help you user and make this process more clear.

**Prerequisites:**\
\- AWS

## Create Security Group

This is first step one, create security group with the following inbound outbound rules, which we’ll discuss details in steps

Steps ->

1. Go to Security groups by any of the following way
   1. AWS Console → Services → EC2 → Security Groups ( Left panel )
   2. Link: [Here](https://www.notion.so/Node-on-EC2-1193361002a780e782fbdbfc6e920b18?pvs=21)
2. Then follow the guide in images, which allow inbound and outbound traffic for your instance
   1. **Inbound Traffic**
      * **SSH (Port 22):** Needed for secure connection.
      * **HTTP (Port 80):** For web access.
      * **HTTPS (Port 443):** For secure web access.
   2. **Outbound traffic**
      * **SSH (Port 22)**

<div data-full-width="false"><figure><img src="/files/Esmkp05nHU13pyzSPUZ9" alt=""><figcaption></figcaption></figure></div>

<div data-full-width="true"><figure><img src="/files/AW8F4krtZ0VWlQ7rZlXx" alt="" width="563"><figcaption></figcaption></figure></div>

***

## Launch AWS Instance

Steps ->

1. **Go to EC2 Dashboard:**
   * In the top search bar, type **EC2** and click on **EC2 Dashboard**.
2. **Launch an EC2 Instance:**
   * Click on **Launch Instance**.
   * **Name Your Instance:** Enter a name like `PlayAI-Server`.
   * **Select an Amazon Machine Image (AMI):** Choose **Ubuntu Server 24.04 LTS (64-bit x86)**.
   * **Instance Type:** Choose `t3.medium` or `t2.medium` or any other that have greater or equal 4 GB RAM, which is minimum resource requirements to run PlayAI Node
   * **Key Pair:** If you don’t have one, create a new key pair and download it. This will let you connect to the server securely. You can choose to ignore it if you are not accessing it from local machine. In EC2 you can connect to terminal without Key Pair. But you’ll definitely need it if you are accessing from your local machine or some other machine.
   * **Security Group Settings:** Select existing security group which you created in previous step
   * **Storage:** Set the storage size to 20GB (or more if you think you'll need it).

<figure><img src="/files/U8RHt7GzVE5dCXwCPdO4" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/F6NIG5dhYChpY3raEcty" alt=""><figcaption></figcaption></figure>

3. **Go to EC2 Dashboard:**

   Once all settings are in place, click Launch Instance. It will take a minute or two to start.

***

## Connect to EC2 Instance

This step will help you connect to ec2 instance, in other word, it gives you terminal to run all the commands for setting up PlayAI node

AWS provides a way to connect to your instance directly from your browser without needing to download any software.

Steps ->

1. **Go to Your Instance:**
   * Once your instance is running (you'll see it in the **Instances** list), select it.
2. **Connect to the Instance:**
   * Click **Connect** at the top of the page.
   * Select the **EC2 Instance Connect** option (this lets you connect via your browser). There are two option available, keep default if you don’t know which one to choose.
   * Click **Connect** — a new window will open with a terminal.
3. You’ll see a terminal there, run below command to see everything is fine upto now

```python
echo "Hi, I am connected to EC2" 
```

***

## Host Machine Setup

In this step, we’ll work on installing required software for smoothly running PlayAI node. Which is installing docker, docker-compose, git. Follow step by step to avoid trouble

Steps ->

1. **Update the Server:**
   * Run the following command to make sure everything is up to date, this will update some basic setting and add some linux channel and all, nothing specific to our setting

     ```bash
     sudo apt update
     sudo apt upgrade -y
     ```
2. **Install Docker:**
   * This step would install docker, which is needed to run AI engines provided by PlayAI. Run below command to install

     ```bash
     sudo apt install docker.io -y
     ```
3. **Install Docker Compose:**
   * Docker compose is a way to run multi container setup in a managed way, which help us define configurations and mount volumes and much more. Install Docker Compose with this command:

     ```bash
     sudo curl -SL <https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-linux-x86_64> -o /usr/local/bin/docker-compose
     sudo chmod +x /usr/local/bin/docker-compose
     ```
4. **Verify Docker and Docker Compose are Installed:**
   * Check Docker version by running:

     ```bash
     docker --version
     ```
   * Check Docker Compose version by running:

     ```bash
     docker-compose --version
     ```

***

## Run PlayAI Node

Now all the dependency part is sorted and we are moving towards the steps to run a PlayAI node. Below is step by steps guide to run a node, which include downloading repo from PlayAI official github page. Make sure to keep node specific values ready that you’ll need in step 5, refer to step 5 for these values.

Steps ->

1. Start to work as root user to avoid sudo all the time, for that you just have to run `sudo -i`

```python
sudo -i 
```

2. Clone the PlayAI Node Client repository using

```python
git clone <https://github.com/PlayAINetwork/PlayAI-Node-Client.git> 
```

3. Navigate to the cloned directory using

```python
cd PlayAI-Node-Client
```

4. **Create and Configure `.env`** add your wallet address, signer key, main server address, and node token ID.
5. Run below command to open file in write mode and paste and setup the below variables then press `CTRL + X` then `Y` and then `Enter` to save this file

```python
nano .env 
```

```python
NODE_WALLET_ADDRESS='xx'
NODE_SIGNER_KEY='xx'
NODE_TOKEN_IDS=[x,x]
```

6. Pulling latest Node Client Containers, you’ll see some logs in the terminal, that confirms that you’re pulling latest container. This step is required to pull latest container, even if you are not setting it first time and you want to pull latest updates just run below command

```python
docker-compose pull 
```

7. Now we have container ready, start the node in detached mode using

```python
docker-compose up -d 
```

8. Check if the node is running using `docker ps`. Expect to see the node container listed

```python
docker ps 
```

Sample output from running this command

<figure><img src="/files/IIe5TEB3BEn5D3jb8vHW" alt=""><figcaption></figcaption></figure>

9. Shutting down all services ( Do not use CTRL+C or Command+C to shut down nodes )

```python
docker-compose down 
```

10. To see live logs run below command ( optional ). This will show live logs of what’s happening with node, it will show some requests are coming and something is saving back to our database and all. Which confirm finally that your node is health and running and getting computations requests from our backends

```python
docker-compose logs -f 
```

11. For closing live logs press `ctrl + C`. Don’t use `ctrl + c` to shut down the node service, use docker-compose down only which will remove some of the unnecessary files from last and you’ll have fresh node live whenever you start node again.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.playai.network/oasis-nodes/how-to-run-the-node/setup-via-ec2-instance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
