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.containerInvoker
role.
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. -
Select Serverless Containers.
-
In the left-hand panel, select
Triggers. -
Click Create trigger.
-
Under Basic settings:
- Enter the trigger name:
timer
. - In the Type field, select
Timer
. - In the Launched resource field, select
Container
.
- Enter the trigger name:
-
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 command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
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 rights 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
, select the folder with your container. - Select 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.