---
name: azion-how-to-run-scripts-on-edge-nodes
description: >-
  Learn how to configure and install Azion CLI on edge nodes using Shell Script resources via Azion Console and API, including service binding and setup.
---

# How to run scripts on edge nodes

To be able to orchestrate services on your device, you must configure all the resources needed to install, uninstall, and reload your services.

This guide presents how to install [Azion CLI](/en/documentation/devtools/cli/) on your edge nodes through a resource of the type `Shell Script` configured on a specific edge service.

---

## Requirements

- An edge node with **Orchestrator Agent** installed and authorized.
- The Dpkg package manager installed on this node.

[Go to how to install Orchestrator agent](/en/documentation/guides/application-development/automation/install-orchestrator-agent/)

[Go to how to authorize an edge node](/en/documentation/guides/application-development/automation/authorize-an-edge-node/)

> **Note**
>
> You can find the download links to the respective architectures on [Azion CLI's releases page](https://github.com/aziontech/azion/releases). You must choose the correct download link based on the architecture of your edge node and replace the `BINARY_URL` in the script with the correct URL.

---

## Creating an edge service

**Console**

1. Access [Azion Console](/en/documentation/guides/platform/account-and-billing/how-to-access-azion-console/).
2. On the upper-left corner of the page, open the **Products menu**, represented by three horizontal lines, and then select **Edge Services**.
3. Click on the **+ Service** button.
4. Name this service `Azion CLI Installation`.
5. Enter the variables and values for the resource, if necessary.
6. Set the status as **Active**.
7. Click the **Save** button.

**API**

1. Run the following `POST` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/) and informing the name of the service being created:

```bash
curl --location 'https://api.azionapi.net/edge_services/' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
  "name": "Azion CLI Installation"
}'
```

2. Keep the ID of the edge service you've just created. You can access it in the response body, for example:

```json
{
    "id": 1196,
    "name": "Azion CLI Installation",
    "updated_at": "2024-01-18T17:24:33Z",
    "last_editor": "xxxxx",
    "active": false,
    "bound_nodes": 0,
    "permissions": [
        "read",
        "write"
    ]
}
```

> **Note**
>
> When running the request in the terminal, the response might not return formatted as presented on the example above.

3. Run the following `PATCH` request in your terminal to set the service as active, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/):

```bash
curl --location --request PATCH 'https://api.azionapi.net/edge_services/:id' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
  "active": true,
  "name": "Azion CLI Installation",
  "variables": [
    {
      "name": "string",
      "value": "string"
    }
  ]
}'
```

> **Note**
>
> If an edge service isn't set as active, it isn't available for binding to an edge node.

---

## Creating a resource

**Console**

1. Inside the service you've just created, called `Azion CLI Installation`, go to the **Resources** tab.
2. Click on **+ Resource**.
3. Enter `/scripts/install-cli` in the **Path** field.
4. Choose the type **Shell Script**.
5. Choose the trigger **Install**.
6. Add the following content to the **Content** block:

```bash
#!/bin/bash

# Define the URL of the binary to download
BINARY_URL="https://github.com/aziontech/azion/releases/download/1.10.2/azion_1.10.2_linux_arm64.deb"

# Download the binary
wget $BINARY_URL -O /tmp/azion.deb

# Install the binary
# This assumes that you have dpkg installed on your system
sudo dpkg -i /tmp/azion.deb

# Clean up the downloaded binary
rm /tmp/azion.deb

echo "Installation completed successfully"
```

7. Click the **Save** button.

This script will install the Azion binary in the following path: `/usr/local/bin`

**API**

1. Run the following `POST` request in your terminal:

```bash
curl --location 'https://api.azionapi.net/edge_services/:id/resources' --header 'Accept: application/json; version=3' --header 'Authorization: Token [TOKEN VALUE]' --header 'Content-Type: application/json' --data '{
  "content_type": "Shell Script",
  "name": "/scripts/install-cli/",
  "content": "#!/bin/bash

# Define the URL of the binary to download
BINARY_URL="https://github.com/aziontech/azion/releases/download/1.10.2/azion_1.10.2_linux_arm64.deb"

# Download the binary
wget $BINARY_URL -O /tmp/azion.deb

# Install the binary
# This assumes that you have dpkg installed on your system
sudo dpkg -i /tmp/azion.deb

# Clean up the downloaded binary
rm /tmp/azion.deb

echo "Installation completed successfully""
}'
```

Replace `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/), `:id` with the ID of the edge service and inform the following parameters in the request body:

| Property       | Description                                                                             | Required |
| -------------- | --------------------------------------------------------------------------------------- | -------- |
| `content_type` | Content type of the resource being created                                              | Yes      |
| `name`         | Name of the resource being created                                                      | Yes      |
| `content`      | Content that defines actions performed when the resource state changes in the edge node | Yes      |

---

## Binding an edge service to an edge node

**Console**

1. On the upper-left corner of the page, open the **Products menu**, represented by three horizontal lines, and then select **Edge Nodes**.
2. Select the edge node to which you want to bind a service.
3. Go to the **Services** tab and click the **+ Service** button.
4. Choose the service `Azion CLI Installation` you've created.
5. Click the **Save** button.

**API**

1. Run the following `GET` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/) and retrieve the edge node ID you wish to bind to an edge service:

```bash
curl --location 'https://api.azionapi.net/edge_nodes/' --header 'Accept: application/json; version=3' --header 'Authorization: Token [TOKEN VALUE]'
```

2. Run the following `POST` request in your terminal:

```bash
curl --location 'https://api.azionapi.net/edge_nodes/:id/services' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
  "service_id": :id,
  "variables": [
    {
      "name": "string",
      "value": "string"
    }
  ]
}'
```

Replace `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/), `:id` with the ID of the edge node and inform the ID of the service in the request body:

| Property     | Description                                                     | Required               |
| ------------ | --------------------------------------------------------------- | ---------------------- |
| `service_id` | ID of the edge service being bound to the edge node             | Yes                    |
| `variables`  | Variables to be replaced during the processing on the edge node | No (requires checking) |

---

## Accessing Azion CLI

After this process, in your edge node, access the folder:

```bash
cd /usr/local/bin
```

Run:

```bash
./azion -h 
```

The output will be similar to:

```bash
Azion CLI 1.10.2

DESCRIPTION
  The Azion Command Line Interface is a unified tool to manage your Azion projects and resources

SYNOPSIS
  azion <command> <subcommand> [flags]

EXAMPLES
  $ azion
  $ azion -t azionb43a9554776zeg05b11cb1declkbabcc9la
  $ azion --debug
  $ azion -h
...
```

> **Tip**
>
> Check the [Azion API documentation](https://api.azion.com/) and the [OpenAPI specification](https://github.com/aziontech/azionapi-openapi/) to know more about all features available via API.
