Getting started with Workflows
Written by
Updated at December 16, 2024
Note
Workflows is at the Preview stage. To gain access, submit a request
Using this tutorial, you will create and run a workflow. During the execution of the workflow, the Yandex Cloud Functions functions will be called.
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
Management console
- 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-function
. - Click
Add role and select thefunctions.functionInvoker
role. - Click Create.
Create a function to filter data
Management console
- In the management console
, select Cloud Functions. - Create a function:
- In the top-right corner, click Create function.
- Enter the function name:
filter-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 add the following code into it:module.exports.handler = async function (data, context) { return { id: data.id, name: data.name, email: data.email, }; };
- Under Parameters, specify the following in the field:
- Entry point:
index.handler
- Service account:
sa-for-function
.
- Entry point:
- Click Save changes.
- In the Editor window that opens, select
Create a function to return email addresses
Management console
- In the management console
, select Cloud Functions. - Create a function:
- In the top-right corner, click Create function.
- Enter the function name:
return-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 add the following code into it:module.exports.handler = async function (data, context) { return { result: "OK", emails: data.loaded_users.map(p => p.email) }; };
- Under Parameters, specify the following in the field:
- Entry point:
index.handler
- Service account:
sa-for-function
.
- Entry point:
- Click Save changes.
- In the Editor window that opens, select
Create a workflow
Management console
-
In the management console
, select Serverless Integrations. -
Go to the Workflows tab.
-
In the top-right corner, click Create workflow.
-
Enter a name for the workflow.
-
In the Service Account field, enter the
sa-for-function
service account. -
In the YAML specification field, add the specification shown below. Specify the following in the
functionId
field:- In the
process_user_transform_info
step, thefilter-function
ID. - In the
upload_users
step, thereturn-function
ID.
yawl: "0.1" start: get_users defaultRetryPolicy: maxDelay: 10s retryCount: 2 errorList: - STEP_QUOTA_EXCEEDED steps: get_users: httpCall: url: 'https://jsonplaceholder.typicode.com/\(.resource_type)' method: GET headers: {} query: {} output: '\({loaded_users: .})' next: process_users process_users: foreach: input: \(.loaded_users) output: '\({loaded_users: .})' next: upload_users do: start: process_user_get_info steps: process_user_get_info: httpCall: url: https://jsonplaceholder.typicode.com/users/\(.id) method: GET headers: {} query: {} next: process_user_transform_info output: '\({user: .})' retryPolicy: retryCount: 2 errorList: - HTTP_CALL_500 process_user_transform_info: functionCall: functionId: <function_ID> upload_users: functionCall: functionId: "<function_ID>" input: '\({loaded_users, resource_type})'
- In the
-
Click Create.
Run the workflow
Management console
- Select a workflow.
- In the top-right corner, click Run.
- Enter input data in JSON format:
{ "resource_type": "users" }
- When the workflow status changes from
Running
toCompleted
, the following JSON object will appear in the Output data section:{ "result": "OK", "emails": [ "Sincere@april.biz", "Shanna@melissa.tv", "Nathan@yesenia.net", "Julianne.OConner@kory.org", "Lucio_Hettinger@annie.ca", "Karley_Dach@jasper.info", "Telly.Hoeger@billy.biz", "Sherwood@rosamond.me", "Chaim_McDermott@dana.io", "Rey.Padberg@karina.biz" ] }