[Yandex Cloud documentation](../../index.md) > [Yandex Serverless Integrations](../index.md) > [Getting started](index.md) > EventRouter

# Getting started with EventRouter

{% note info %}

EventRouter is at the [Preview](../../overview/concepts/launch-stages.md) stage.

{% endnote %}

In this tutorial, you will use an EventRouter [bus](../concepts/eventrouter/bus.md) to forward a message from a [Message Queue](../../message-queue/index.md) to a [workflow](../concepts/workflows/workflow.md) in Workflows.

If it matches the filter defined in the rule inside the bus, a message entering the queue will be forwarded to the workflow. The workflow will be executed automatically. Before being forwarded, the message will be converted according to the template defined in the same rule as the filter.

## Getting started {#before-you-begin}

To get started in Yandex Cloud:
1. Log in to the [management console](https://console.yandex.cloud). If not signed up yet, navigate to the management console and follow the on-screen instructions.
1. On the [**Yandex Cloud Billing**](https://center.yandex.cloud/billing/accounts) page, make sure you have a [billing account](../../billing/concepts/billing-account.md) linked and its [status](../../billing/concepts/billing-account-statuses.md) is `ACTIVE` or `TRIAL_ACTIVE`. If you do not have a billing account yet, [create one](../../billing/quickstart/index.md#create_billing_account).
1. If you do not have a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) yet, [create one](../../resource-manager/operations/folder/create.md).

## Create a service account {#create-sa}

{% list tabs group=instructions %}

- Management console {#console}

    1. In the [management console](https://console.yandex.cloud), select the relevant folder.
    1. Navigate to **Identity and Access Management**.
    1. Click **Create service account**.
    1. Name the [service account](../../iam/concepts/users/service-accounts.md): `sa-for-eventrouter`.
    1. Click ![image](../../_assets/console-icons/plus.svg) **Add role** and select the `serverless.workflows.executor`, [ymq.reader](../../iam/roles-reference.md#ymq-reader), and [ymq.writer](../../iam/roles-reference.md#ymq-writer) roles.
    1. Click **Create**. 

{% endlist %}

## Create a queue {#create-queue}

{% list tabs group=instructions %}

- Management console {#console}

    1. Open your [management console](https://console.yandex.cloud) and navigate to **Message Queue**.
    1. Click **Create queue**.
    1. Enter a name for the queue: `sample-queue`.
    1. Select the `Standard` type. Do not change other settings.
    1. Click **Create**.
    1. Open the queue you created.
    1. In the **Overview** tab, under **General information**, copy the queue URL as you will need it later.

{% endlist %}

## Create a workflow {#create-workflow}

{% note info %}

Workflows is at the [Preview](../../overview/concepts/launch-stages.md) stage.

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

    1. Open your [management console](https://console.yandex.cloud) and navigate to **Serverless Integrations**.
    1. In the left-hand panel, select ![GraphNode](../../_assets/console-icons/graph-node.svg) **Workflows**.
    1. In the top-right corner, click **Create workflow**.
    1. In the **YaML specification** field, add the specification as follows:
        ```
        yawl: "0.1"
        start: noopstep
        steps:
          noopstep:
            noOp:
              output: |-
                \(.)
        ```
    1. Expand the **Additional parameters** section.
    1. In the **Name** field, enter the workflow name: `sample-workflow`.
    1. In the **Service account** field, select `sa-for-eventrouter`.
    1. Click **Create**.

{% endlist %}

## Create a bus {#create-bus}

{% list tabs group=instructions %}

- Management console {#console}

    1. Open your [management console](https://console.yandex.cloud) and navigate to **Serverless Integrations**.
    1. In the left-hand panel, select ![ObjectAlignCenterVertical](../../_assets/console-icons/object-align-center-vertical.svg) **EventRouter**.
    1. In the top-right corner, click **Create bus**.
    1. Enter the bus name: `sample-bus`.
    1. Click **Create**.

{% endlist %}

## Create a connector {#create-connector}

{% list tabs group=instructions %}

- Management console {#console}

    1. Select the `sample-bus` bus.
    1. Navigate to the **Connectors** tab.
    1. In the top-right corner, click **Create connector**.
    1. In the **Source** field, select `Yandex Message Queue`.
    1. Specify `sample-queue` in the **Message queue** field.
    1. In the **Service account** field, specify `sa-for-eventrouter`.
    1. Click **Create**.

{% endlist %}

## Create a rule {#create-rule}

{% list tabs group=instructions %}

- Management console {#console}

    1. Select the `sample-bus` bus.
    1. Navigate to the **Rules** tab.
    1. In the top-right corner, click **Create rule**.
    1. Expand the **Filter** section and specify the following jq template to filter messages:
        ```
        .httpMethod == "GET" and (.headers.Host | test("^d5dm"))
        ```
    1. Under **Targets**, click **Add**.
    1. In the **Type** field, select `Yandex Workflows`.
    1. In the **Workflow** field, specify `sample-workflow`.
    1. In the **Service account** field, specify `sa-for-eventrouter`.
    1. Expand the **Transformer** section and specify the jq template to convert messages:
        ```
        {
           "message": "API gateway host is \(.headers.Host)."
        }
        ```
    1. Click **Create**.

{% endlist %}

## Send a message to the queue {#send-message}

Make sure the messages matching the created rule are converted and forwarded to the workflow.

{% list tabs group=instructions %}

- AWS CLI {#cli}

    1. [Install](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) the AWS CLI.
    1. [Create](../../iam/operations/authentication/manage-access-keys.md#create-access-key) static access keys for the `sa-for-eventrouter` service account. Save the ID and secret key to a secure location. You will not be able to view the secret key parameters again after you close the window.
    1. Configure the AWS CLI:

       1. Launch the interactive profile setup:
       
          ```bash
          aws configure
          ```
       
       1. Specify the service account key ID you obtained earlier:
       
          ```bash
          AWS Access Key ID [****************ver_]: <service_account_key_ID>
          ```
       
       1. Specify the service account secret key you obtained earlier:
       
          ```bash
          AWS Secret Access Key [****************w5lb]: <service_account_secret_key>
          ```
       
       1. Specify the `ru-central1` default region name:
       
          ```bash
          Default region name [ru-central1]: ru-central1
          ```
       
       1. Specify `json` as the default format for output data:
       
          ```bash
          Default output format [None]: json
          ```
       
       1. To view the current profile settings, run this command:
       
          ```bash
          aws configure list
          ```
       
          Result:
       
          ```text
                Name                    Value             Type    Location
                ----                    -----             ----    --------
             profile                <not set>             None    None
          access_key     ****************aBc1 shared-credentials-file
          secret_key     ****************DeF2 shared-credentials-file
              region              ru-central1      config-file    ~/.aws/config
          ```

    1. Send the first message to `sample-queue` using the previously saved queue URL:

        ```bash
        aws sqs send-message \
          --message-body '{"httpMethod":"GET","headers":{"Host":"h6ds1lb3s0df********.k7******.apigw.yandexcloud.net"}}' \
          --endpoint https://message-queue.api.cloud.yandex.net/ \
          --queue-url <queue_URL>
        ```

         Result:
         
        ```json
        {
            "MD5OfMessageBody": "c37859ba35a9958be041467c********",
            "MessageId": "f845****-9260****-7527****-f4b0****",
            "SequenceNumber": "0"
        }
         ```
    1. Make sure the filter you specified in the rule stopped the message from going through the bus:

        1. Open your [management console](https://console.yandex.cloud) and navigate to **Serverless Integrations**.
        1. In the left-hand panel, select ![GraphNode](../../_assets/console-icons/graph-node.svg) **Workflows**.
        1. Navigate to the **Executions** tab. You should not see any completed executions on the page.

    1. Send the second message to `sample-queue` using the previously saved queue URL:

        ```bash
        aws sqs send-message \
          --message-body '{"httpMethod":"GET","headers":{"Host":"d5dm1lba80md********.i9******.apigw.yandexcloud.net"}}' \
          --endpoint https://message-queue.api.cloud.yandex.net/ \
          --queue-url <queue_URL>
        ```

        Result:
         
        ```json
        {
            "MD5OfMessageBody": "c37859ba35a9958be041467c********",
            "MessageId": "f845****-9260****-7527****-f4b0****",
            "SequenceNumber": "0"
        }
         ```
    1. Make sure the filter you specified in the rule allowed the message to go through the bus and then the message was converted according to the template and forwarded to the workflow:

        1. Open your [management console](https://console.yandex.cloud) and navigate to **Serverless Integrations**.
        1. In the left-hand panel, select ![GraphNode](../../_assets/console-icons/graph-node.svg) **Workflows**.
        1. Navigate to the **Executions** tab. You should now see a completed execution on the page.
        1. Select the completed execution.
        1. Make sure the **Input data** section displays the converted message:
            ```
            {
               "message": "API gateway host is d5dm1lba80md********.i9******.apigw.yandexcloud.net."
            }
            ```

{% endlist %}

## What's next {#what-is-next}

* [Read about the EventRouter concepts](../concepts/eventrouter/bus.md).