Creating a timer that invokes a container
Create a timer that invokes a Serverless Containers container every minute.
Getting started
- Create a container to be invoked by your timer. Application and Dockerfile examples.
- Create a service account that will be used to invoke the container and assign it the
serverless-containers.containerInvokerrole.
Create a timer
Note
The trigger is initiated within 5 minutes of being created.
-
In the management console
, select the folder where you want to create a timer. -
Go to Serverless Containers.
-
In the left-hand panel, select
Triggers. -
Click Create trigger.
-
Under Basic settings:
- Enter a name for the trigger:
timer. - In the Type field, select
Timer. - In the Launched resource field, select
Container.
- Enter a name for the trigger:
-
Under Timer settings, enter
* * ? * * *or selectEvery minute. -
Under Container settings, select a container and specify a service account to invoke it under.
-
Click Create trigger.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To create a trigger that invokes a container every minute, run this command:
yc serverless trigger create timer \
--name timer \
--cron-expression '* * ? * * *' \
--invoke-container-id <container_ID> \
--invoke-container-service-account-id <service_account_ID>
Where:
--name: Timer name.--cron-expression: Container invocation schedule specified as a cron expression.--invoke-container-id: Container ID.--invoke-container-service-account-id: ID of the service account with permissions to invoke the container.
Result:
id: a1sp9tj1jhar********
folder_id: b1g4j6o69kqj********
created_at: "2023-03-16T17:45:23.145213360Z"
name: timer
rule:
timer:
cron_expression: '* * ? * * *'
invoke_container_with_retry:
container_id: bbavvhra8ekc********
service_account_id: aje1ki4ae68u********
status: ACTIVE
You can create a timer using the create API method.
Check the result
To make sure the timer is running properly, view the container logs. They should show that the container is invoked every minute.
- In the management console
, go to the folder with your container. - Go to Serverless Containers.
- Click the container to view its invocation log.
- In the window that opens, go to Logs and specify the period to view them for. The default period is 1 hour.