---
name: azion-instantiate-a-function-on-an-application
description: >-
  Bind a function to an application from Azion Console or the Azion API, name the instance, and pass its Args in JSON.
---

# Instantiate a function on an application

You can create a function instance on an application from Azion Console or the Azion API. The instance binds one function to one application and carries the Args passed into the execution context.

An instance without a Rules Engine rule never runs. The rule selects the instance with the **Run Function** behavior and sets the criteria that trigger it. To add that rule, refer to [Run a function on an application](/en/documentation/guides/application-development/functions-and-runtime/serverless-functions/).

To create the same object on a firewall, refer to [Instantiate a function on a firewall](/en/documentation/guides/application-security/firewall-and-waf/instantiate-functions/).

---

## Prerequisites

- An application. To create one, refer to [Applications quickstart](/en/documentation/platform/applications/quickstart/).
- A function on the account. Take one from [Azion Marketplace](/en/documentation/platform/marketplace/), or write one, as in the [Functions quickstart](/en/documentation/platform/functions/quickstart/).
- A [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/), for the API path.

> **Caution**
>
> Computing time and invocations for functions generate usage-related costs. For the rates, refer to [Pricing](/en/documentation/fundamentals/pricing/).

---

## Create the function instance

An application runs a function through an instance, and one function can back several instances. Each path turns on the **Functions** module for the application, then creates the instance:

**Console**

To create the instance from Azion Console:

1. **Open the application**

   Access [Azion Console](https://console.azion.com/) > **Applications** > **your application**.

2. **In the Main Settings tab, turn on the Functions module**

3. **Select Save**

4. **Go to the Functions Instances tab**

5. **Select + Function Instance**

6. **Name the instance**

   Enter a name for the instance. For example: `hello-world instance`.

7. **Select the function**

   Select the function the instance runs. For example, the pre-configured *Azion - Hello World* function.

8. **Enter the Args**

   (Optional) In the **Args** tab, enter the arguments for the instance in JSON.

9. **Select Save**

The instance appears in the **Functions Instances** tab. It does not run until a Rules Engine rule selects it.

**API**

To create the instance with the Azion API:

1. **Turn on the Functions module**

   Send a `PATCH` request to the application, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/) and `<application_id>` with [your application ID](/en/documentation/guides/application-development/getting-started/configure-main-settings/):

   ```bash
   curl --request PATCH \
     --url https://api.azion.com/v4/workspace/applications/<application_id> \
     --header 'Accept: application/json' \
     --header 'Authorization: Token [TOKEN VALUE]' \
     --header 'Content-Type: application/json' \
     --data '{
     "modules": {
       "functions": {
         "enabled": true
       }
     }
   }'
   ```

   The response returns the updated value.

2. **Read the ID of the function**

   Send a `GET` request to the functions endpoint:

   ```bash
   curl --request GET \
     --url https://api.azion.com/v4/workspace/functions \
     --header 'Accept: application/json' \
     --header 'Authorization: Token [TOKEN VALUE]'
   ```

   The response lists the functions on the account. Copy the `id` of the function to instantiate:

   ```json
   {
     "count": 1,
     "results": [
       {
         "id": <function_id>,
         "name": "My Function",
         "last_editor": "your-email@example.com",
         "last_modified": "2025-08-14T16:37:54.966088Z",
         "product_version": "2.0",
         "active": true,
         "runtime": "azion_js",
         "execution_environment": "application",
         "code": "",
         "default_args": {},
         "reference_count": 0,
         "version": "-",
         "vendor": null
       }
     ]
   }
   ```

3. **Create the instance**

   Send a `POST` request to the functions resource of the application, replacing `<function_id>` with the ID you copied:

   ```bash
   curl --request POST \
     --url https://api.azion.com/v4/workspace/applications/<application_id>/functions \
     --header 'Accept: application/json' \
     --header 'Authorization: Token [TOKEN VALUE]' \
     --header 'Content-Type: application/json' \
     --data '{
     "name": "My instance Name",
     "function": <function_id>,
     "args": {},
     "active": true
   }'
   ```

   The response returns the instance that the application now carries:

   ```json
   {
     "state": "pending",
     "data": {
       "id": <function_instance_id>,
       "name": "My Function Instance",
       "args": {},
       "function": 123456,
       "active": true,
       "last_editor": "your-email@example.com",
       "last_modified": "2025-08-14T16:41:56.699896Z"
     }
   }
   ```

The instance exists on the application, and the response carries its fields:

| Key        | Description                                                                                       |
| ---------- | ------------------------------------------------------------------------------------------------- |
| `id`       | The ID of the function instance                                                                   |
| `name`     | The name of the function instance                                                                 |
| `function` | The ID of the function the instance runs. It differs from `id`, which is unique for each instance |
| `args`     | The arguments passed into the execution context of the function. Some functions take no arguments |

The `"state": "pending"` value means the change takes a few minutes to propagate before it takes effect. The instance does not run until a Rules Engine rule selects it.

> **Tip**
>
> For every endpoint and its fields, refer to the [Azion API documentation](https://api.azion.com/) and the [OpenAPI specification](https://github.com/aziontech/azionapi-openapi/).

---

## Instance Args

Args are the arguments an instance passes into the context of the function's execution, written as a JSON object. The code of the function cannot be changed at instantiation, so Args are how one function behaves differently in each application that instantiates it. An Args object that sets one key:

```json
{
  "value": "hello_world"
}
```

The code reads the key at run time and the instance decides its value. A function can define default Args of its own, and the Args of an instance override the keys they repeat. The Args object holds a maximum of 100 KB, and an object above that ceiling makes the function fail at instantiation. Sensitive values such as API keys, credentials, and access tokens belong in [environment variables](/en/documentation/platform/functions/environment-variables/) instead.

For the default values and the override rules, refer to [How Functions works](/en/documentation/platform/functions/how-it-works/). For every field of the instance object, refer to [Function instances](/en/documentation/platform/applications/functions-instances/).

---

## Next steps

- [Run a function on an application](/en/documentation/guides/application-development/functions-and-runtime/serverless-functions.md): Add the Rules Engine rule that runs the instance, from Azion Console or the Azion API.
- [Create an application rule](/en/documentation/guides/application-development/getting-started/work-with-rules-engine.md): The rule that selects the instance, from Azion Console or the Azion API.
- [Function instances](/en/documentation/platform/applications/functions-instances.md): Every field of the instance object, the Args ceiling, and the Run Function behavior.
- [Using args](/en/documentation/platform/functions/using-args.md): A function that reads a key from its Args and answers with the value.
