Getting started with EventRouter
In this guide, you will create a queue in Message Queue and send a message to it. This message will be transmitted to a Cloud Functions function via a bus.
Getting started
To get started in Yandex Cloud:
- Log in to the management console
. If not signed up yet, navigate to the management console and follow the instructions. - On the Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not have a billing account yet, create one. - If you do not have a folder yet, create one.
Create a service account
- In the management console
, select the appropriate folder. - In the list of services, select Identity and Access Management.
- Click Create service account.
- Enter a name for the service account:
sa-for-eventrouter
. - Click
Add role and select thefunctions.functionInvoker
,ymq.reader
, andymq.writer
roles. - Click Create.
Create a queue
- In the management console
, select Message Queue. - Click Create queue.
- Enter a name for the queue:
sample-queue
. - Select the
Standard
type. Do not change other settings. - Click Create.
- Open the queue you created.
- On the Overview tab under General information, copy the queue URL and ARN for later use.
Create a function
- In the management console
, select Cloud Functions. - Create a function:
- In the top-right corner, click Create function.
- Enter the function name:
eventrouter-function
. - Click Create.
- Create a function version:
- In the Editor window that opens, select
Node.js 18
. - Disable the Add files with code examples option.
- Click Continue.
- Create a file named
index.js
and paste the following code into it:module.exports.handler = async function (event, context) { console.log(JSON.stringify(event)) return { statusCode: 200, body: "", }; };
- Under Parameters, specify the following in the field:
- Entry point:
index.handler
- Service account:
sa-for-eventrouter
- Entry point:
- Click Save changes.
- In the Editor window that opens, select
Create a bus
- In the management console
, select Serverless Integrations. - Go to the EventRouter tab.
- In the top-right corner, click Create bus.
- Enter a name for the bus and click Create.
Create a connector
- Select a bus.
- Go to the Connectors tab.
- In the top-right corner, click Create connector.
- Under Source, select
Yandex Message Queue
. - Specify the queue ARN in the Message queue field.
- In the Service account field, specify
sa-for-eventrouter
. - Click Create.
Create a rule
- Select a bus.
- Go to the Rules tab.
- In the top-right corner, click Create rule.
- Under Targets, click Add.
- In the Type field, select
Yandex Cloud Functions
. - In the Function field, specify
eventrouter-function
. - In the Service account field, specify
sa-for-eventrouter
. - Click Create.
Send a message to the queue
-
Install
the AWS CLI. -
Create 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. -
Set up the AWS CLI:
-
Launch the interactive profile setup:
aws configure
-
Specify the service account key ID you obtained earlier:
AWS Access Key ID [****************ver_]: <service_account_key_ID>
-
Specify the service account secret key you obtained earlier:
AWS Secret Access Key [****************w5lb]: <service_account_secret_key>
-
Specify the
ru-central1
default region name:Default region name [ru-central1]: ru-central1
-
Specify
json
as the default format for output data:Default output format [None]: json
-
To view the current profile settings, run this command:
aws configure list
Result:
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
-
-
Send a message to
sample-queue
using the previously saved queue URL:aws sqs send-message \ --message-body "Hello World" \ --endpoint https://message-queue.api.cloud.yandex.net/ \ --queue-url <queue_URL>
Result:
{ "MD5OfMessageBody": "67e63db14341b5a696596634********", "MessageId": "765ff4d2-fa4bc83-6cfcc***-*****" }
Check that the function was invoked
- In the management console
, select Cloud Functions. - Select the
eventrouter-function
function. - Go to the Logs tab. The messages you sent to the queue must appear in logs.