Creating triggers that invoke Cloud Functions functions to stop a VM and send Telegram notifications
- Prepare your cloud
- Create a budget
- Create a Message Queue
- Create a Cloud Functions function to be invoked by the budget trigger
- Create a trigger for budgets
- Register the Telegram bot
- Create a Cloud Functions function to be invoked by the Message Queue budget trigger
- Create a trigger for Message Queue
- Create Compute Cloud VMs
- Make sure the trigger stops VMs and sends Telegram notifications
- How to delete the resources you created
In this tutorial, you will create a serverless infrastructure that will stop running virtual machines when budget thresholds are exceeded and send Telegram notifications to the user.
The budget trigger will invoke the Cloud Functions function, and this function will stop the Compute Cloud virtual machines and send a message to the Yandex Message Queue queue.
The Message Queue trigger will provide the queued messages to the second Cloud Functions function, which will send Telegram notifications via a dedicated bot.
To deploy a project:
- Prepare your cloud.
- Create a budget.
- Create a Message Queue queue.
- Create a Cloud Functions function to be invoked by the budget trigger.
- Create a trigger for budgets.
- Register the Telegram bot.
- Create a Cloud Functions function to be invoked by the Message Queue budget trigger.
- Create a trigger for Message Queue.
- Create Compute Cloud VM instances.
- Make sure the trigger stops VMs and sends Telegram notifications.
Create all the specified Yandex Cloud resources in the same folder.
If you no longer need the resources you created, delete them.
Prepare your cloud
Sign up for Yandex Cloud and create a billing account:
- Go to the management console
and log in to Yandex Cloud or create an account if you do not have one yet. - On the Yandex Cloud 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, create one.
If you have an active billing account, you can go to the cloud page
Learn more about clouds and folders.
Required paid resources
The cost of resources includes:
- Fee for VM computing resources (see Compute Cloud pricing).
- Fee for VM disks (see Compute Cloud pricing).
- Fee for using a dynamic public IP address (see Yandex Virtual Private Cloud pricing).
- Fee for the number of function calls, computing resources allocated to a function, and outgoing traffic (see Cloud Functions pricing).
- Fee for the number of requests to queues and outgoing traffic (see Message Queue pricing).
- Fee for logging operations and data storage in a log group (see Yandex Cloud Logging pricing) if using Cloud Logging.
Download a project
Clone the repository with the project:
git clone https://github.com/yandex-cloud-examples/yc-telegram-bot-with-trigger-for-budget
Create a service account and static access key
-
Create a service account:
Management consoleCLIAPI- In the management console
, select your folder. - In the list of services, select Identity and Access Management.
- Click Create service account.
- In the Name field, specify the name:
service-account-for-budget
. - In the Roles in the folder field, click
Add role and select theeditor
role. - Click Create.
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.-
Create a service account named
service-account-for-budget
:yc iam service-account create \ --name service-account-for-budget
Result:
done (1s) id: ajed1o6dd581******** folder_id: b1g9d2k0itu4******** created_at: "2024-02-23T18:32:38.365175925Z" name: service-account-for-budget
Save the service account ID (
id
): you will need it in the next step.For more information about the
yc iam service-account create
command, see the CLI reference. -
Assign the service account the
editor
role for your folder:yc resource-manager folder add-access-binding <folder_ID> \ --role editor \ --subject serviceAccount:<service_account_ID>
Where:
<folder_name>
: Name of your folder in Yandex Cloud.<service_account_ID>
: Previously saved service account ID.
Result:
done (2s) effective_deltas: - action: ADD access_binding: role_id: editor subject: id: ajed1o6dd581******** type: serviceAccount
For more information about the
yc resource-manager folder add-access-binding
command, see the CLI reference.
To create a service account, use the create REST API method for the ServiceAccount resource or the ServiceAccountService/Create gRPC API call.
To assign the service account a role for the folder, use the updateAccessBindings REST API method for the Folder resource or the FolderService/UpdateAccessBindings gRPC API call.
- In the management console
-
Create a static access key:
Management consoleCLIAPI-
In the management console
, select your folder. -
In the list of services, select Identity and Access Management.
-
In the left-hand panel, select
Service accounts. -
Select the
service-account-for-budget
service account from the list that opens. -
In the top panel, click
Create new key and select Create static access key. -
If required, specify the key description and click Create.
-
Save the ID and secret key.
Alert
After you close the dialog, the key value will become unavailable.
Run this command:
yc iam access-key create \ --service-account-name service-account-for-budget
Result:
access_key: id: aje75gg0rp8k******** service_account_id: ajed1o6dd581******** created_at: "2024-02-23T18:36:41.061060561Z" key_id: YCAJEK_r3Z_EvxRAR******** secret: YCPQhHFMx6rnWXQC9ID425gk3V9YnUc********
Save the ID (
key_id
) and secret key (secret
). You will not be able to get this key value again.For more information about the
yc iam access-key create
command, see the CLI reference.To create an access key, use the create REST API method for the AccessKey resource or the AccessKeyService/Create gRPC API call.
-
Create a cloud network and subnet
- In the management console
, select your folder. - In the list of services, select Virtual Private Cloud.
- At the top right, click Create network.
- In the Name field, specify
my-sample-network
. - In the Advanced field, disable the Create subnets option.
- Click Create network.
- In the left-hand panel, select
Subnets. - At the top right, click Create.
- In the Name field, specify
sample-subnet-ru-central1-b
. - In the Zone field, select the
ru-central1-b
availability zone. - In the Network field, select the
my-sample-network
cloud network. - In the CIDR field, specify
192.168.1.0/24
. - Click Create subnet.
-
Create the
my-sample-network
network:yc vpc network create my-sample-network
Result:
id: enp2gjcvrd59******** folder_id: b1g9d2k0itu4******** created_at: "2024-02-23T18:39:17Z" name: my-sample-network default_security_group_id: enp9uobl2c33********
For more information about the
yc vpc network create
command, see the CLI reference. -
Create a subnet named
sample-subnet-ru-central1-b
in theru-central1-b
availability zone:yc vpc subnet create sample-subnet-ru-central1-b \ --zone ru-central1-b \ --network-name my-sample-network \ --range 192.168.1.0/24
Result:
id: e2l1ejkvq4jv******** folder_id: b1g9d2k0itu4******** created_at: "2024-02-23T18:40:26Z" name: sample-subnet-ru-ru-central1-b network_id: enp2gjcvrd59******** zone_id: ru-central1-b v4_cidr_blocks: - 192.168.1.0/24
For more information about the
yc vpc subnet create
command, see the CLI reference.
-
To create a network, use the create REST API method for the Network resource or the NetworkService/Create gRPC API call.
-
To create a subnet, use the create REST API method for the Subnet resource or the SubnetService/Create gRPC API call.
Create a budget
The user needs the editor
role to create a budget. To get notifications, the viewer
role is sufficient.
-
Go to Yandex Cloud Billing
. -
Select a billing account.
-
In the General information section, in the ID field, copy the billing account ID. You will need it when creating a trigger for budgets.
-
Go to the Budgets tab and click Create budget.
-
Under General information, specify:
-
Name:
vm-budget
. -
Type:
Due and payable
. -
Amount: Amount of consumption expenses, e.g.
₽10
. -
Calculation period:
Monthly
. -
Expires: Budget expiration date.
The end date is when the budget stops calculating usage and sending notifications. The end date is the last day of the month. It must be within five years of the current date.
-
Notify: Select yourself.
-
-
Under Scope, select your current folder and the Compute Cloud service.
-
Under Limits, set the threshold values as a percentage upon reaching which:
- Specified users will get notifications.
- Trigger for budgets will fire.
For example, you can set two thresholds:
50%
and100%
. -
Click Create.
-
A window will open with the new
vm-budget
. In the ID field, copy the ID of the new budget. You will need it later when creating a trigger.
To create a budget, use the create method for the Budget resource or the BudgetService/Create gRPC API call.
Create a Message Queue
-
In the management console
, select your folder. -
Select Message Queue.
-
Click Create queue.
-
Under Basic parameters, specify:
- Name:
budget-queue
. - Type:
Standard
.
Leave the other parameters unchanged.
- Name:
-
Click Create.
-
Click the name of the new
budget-queue
and copy the field values in the window that opens:- URL: Queue URL
- ARN: Queue ID
Save these values: you will need them in the next steps.
-
Install and configure the AWS CLI. When configuring, use the previously created static access key.
-
Create a queue:
aws sqs create-queue \ --queue-name budget-queue \ --endpoint https://message-queue.api.cloud.yandex.net/
Result:
{ "QueueUrl": "https://message-queue.api.cloud.yandex.net/b1glti4eser3********/dj600000001c********/budget-queue" }
Save the
QueueUrl
value, you will need it in the next steps. -
Get the queue ID by specifying the previously saved URL in the
--queue-url
parameter:aws sqs get-queue-attributes \ --queue-url <queue_URL> \ --attribute-names QueueArn \ --endpoint https://message-queue.api.cloud.yandex.net/
Result:
{ "Attributes": { "QueueArn": "yrn:yc:ymq:ru-central1:b1g9d2k0itu4********:budget-queue" } }
Save the
QueueArn
queue ID, you will need it in the next steps.
Create a Cloud Functions function to be invoked by the budget trigger
-
Prepare a ZIP archive with the function code.
Go to the
yc-telegram-bot-with-trigger-for-budget/steps/4-create-budget-trigger-handler
directory and add files to thesrc_bgt.zip
archive:zip src_bgt.zip budget_trigger_handler.go go.mod
-
Create a function:
Management consoleCLIAPI-
In the management console
, select your folder. -
Select Cloud Functions.
-
Create a function:
- Click Create function.
- Enter the function name:
budget-trigger-handler
. - Click Create.
-
Create a function version:
-
Select
golang119
as the runtime environment, disable the Add files with code examples option, and click Continue. -
Specify the ZIP archive upload method and attach the
src_bgt.zip
archive created in the previous step. -
Specify the entry point:
budget_trigger_handler.Handler
. -
Under Parameters, specify:
- Timeout, sec:
5
- Memory:
512 MB
- Service account:
service-account-for-budget
- Environment variables:
FOLDER_ID
: ID of the folder to stop the VMs in.TAG
:target-for-stop
.AWS_ACCESS_KEY_ID
: Static access key ID value saved previously.AWS_ACCESS_KEY_ID
: Private key value of the static access key saved previously.BUDGET_QUEUE_URL
: Previously saved value of thebudget-queue
URL .
- Timeout, sec:
-
Click Save changes.
-
-
Create the
budget-trigger-handler
function:yc serverless function create \ --name budget-trigger-handler
Result:
id: d4e4aigfdm0b******** folder_id: b1g9d2k0itu4******** created_at: "2024-02-23T20:15:06.456Z" name: budget-trigger-handler http_invoke_url: https://functions.yandexcloud.net/d4e4aigfdm0b******** status: ACTIVE
For more information about the
yc serverless function create
command, see the CLI reference. -
Create a version of the
budget-trigger-handler
function:yc serverless function version create \ --function-name budget-trigger-handler \ --memory=512m \ --execution-timeout=5s \ --runtime=golang119 \ --entrypoint=budget_trigger_handler.Handler \ --service-account-id=<service_account_ID> \ --environment FOLDER_ID=<folder_ID> \ --environment TAG=target-for-stop \ --environment AWS_ACCESS_KEY_ID=<static_key_ID> \ --environment AWS_SECRET_ACCESS_KEY=<private_key_value> \ --environment BUDGET_QUEUE_URL=<queue_URL> \ --source-path="./src_bgt.zip"
Where:
-
--service-account-id
: Previously saved ID of theservice-account-for-budget
service account. The service account will be used to invoke the function. -
--environment
: Environment variables:FOLDER_ID
: ID of the folder to stop the VMs in.AWS_ACCESS_KEY_ID
: Static access key ID value saved previously.AWS_ACCESS_KEY_ID
: Private key value of the static access key saved previously.BUDGET_QUEUE_URL
: Previously saved value of thebudget-queue
URL .
-
--source-path
: Path to thesrc_bgt.zip
archive.
Result:
done (2m32s) id: d4em5gaeev2b******** function_id: d4e4aigfdm0b******** created_at: "2024-02-23T20:31:18.458Z" runtime: golang119 entrypoint: budget_trigger_handler.Handler resources: memory: "536870912" execution_timeout: 5s service_account_id: ajed1o6dd581******** image_size: "23977984" status: ACTIVE tags: - $latest environment: AWS_ACCESS_KEY_ID: YCAJEK_r3Z_EvxRAR******** AWS_SECRET_ACCESS_KEY: YCPQhHFMx6rnWXQC9ID425gk3V9YnUc0******** BUDGET_QUEUE_URL: https://message-queue.api.cloud.yandex.net/b1glti4eser3********/dj600000001c********/budget-queue FOLDER_ID: b1g9d2k0itu4******** TAG: target-for-stop log_options: folder_id: b1g9d2k0itu4********
For more information about the
yc serverless function version create
command, see the CLI reference. -
To create a function, use the create method for the Function resource or the FunctionService/Create gRPC API call.
To create a function version, use the createVersion method for the Function resource or the FunctionService/CreateVersion gRPC API call.
-
Create a trigger for budgets
-
In the management console
, select your folder. -
Select Cloud Functions.
-
In the left-hand panel, select
Triggers. -
Click Create trigger.
-
Under Basic settings:
- In the Name field, specify the trigger name:
trigger-for-budget-from-yc
. - In the Type field, select
Budget
. - In the Launched resource field, select
Function
.
- In the Name field, specify the trigger name:
-
Under Budget settings, select your billing account and the
vm-budget
budget you created earlier. -
Under Function settings, select the
budget-trigger-handler
function and specify theservice-account-for-budget
service account. It will be used to invoke the function. -
Click Create trigger.
To create a budget trigger that invokes the budget-trigger-handler
function, run the following command:
yc serverless trigger create billing-budget \
--name trigger-for-budget-from-yc \
--invoke-function-name budget-trigger-handler \
--invoke-function-service-account-id <service_account_ID> \
--billing-account-id <billing_account_ID> \
--budget-id <budget_ID>
Where:
--invoke-function-service-account-id
: Previously saved ID of theservice-account-for-budget
service account. The service account will be used to invoke the function.--billing-account-id
: Billing account ID saved earlier when creating a budget.--budget-id
: Previously saved budget ID.
Result:
id: a1sjrukc64hs********
folder_id: b1g9d2k0itu4********
created_at: "2024-02-23T21:20:03.308963151Z"
name: trigger-for-budget-from-yc
rule:
billing_budget:
billing_account_id: dn276oa9slgm********
budget_id: dn2jr6qt0q9k********
invoke_function:
function_id: d4e4aigfdm0b********
function_tag: $latest
service_account_id: ajed1o6dd581********
status: ACTIVE
For more information about the yc serverless trigger create billing-budget
command, see the CLI reference.
To create a trigger for budgets, use the create method for the Trigger resource or the TriggerService/Create gRPC API call.
Register the Telegram bot
-
Register a bot in Telegram and get a token:
-
To register a new bot, run BotFather
in Telegram and run the following command:/newbot
Result:
Alright, a new bot. How are we going to call it? Please choose a name for your bot.
-
In the next message, enter a name for the bot you are creating, e.g.,
YC VM budget informer
. This is the name users will see when communicating with the bot.Result:
Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.
-
Specify a username for the bot you are creating, e.g.,
YCVMBudgetInformerBot
. You can use the username to search for the bot in Telegram. The name must end with...Bot
or..._bot
. As a result, you will get a token for the HTTP API.Result:
Done! Congratulations on your new bot. You will find it at t.me/YCVMBudgetInformerBot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this. Use this token to access the HTTP API: 715063****:AAGuj****-0VrIm7j9i**************** Keep your token secure and store it safely, it can be used by anyone to control your bot. For a description of the Bot API, see this page: https://core.telegram.org/bots/api
-
-
Get
ChatID
of the user the bot will be sending notifications to:-
Save the API token you got in the previous step to the
TELEGRAM_BOT_API_TOKEN
environment variable:export TELEGRAM_BOT_API_TOKEN=<Telegram_API_token>
-
Go to the
yc-telegram-bot-with-trigger-for-budget/steps/6-register-telegram-bot
directory and run the following command:go run .
If required, pre-install the
Go
andtelegram_bot
packages.The command will run a Telegram bot that will return
ChatID
of the current user in response to any message. -
In Telegram, find the bot you created by username, e.g.,
YCVMBudgetInformerBot
, and send any message to it.Result:
59529*****
Save the obtained
ChatID
. You will need it later. -
Return to the terminal and terminate the bot using the Ctrl + C keyboard shortcut.
-
Create a Cloud Functions function to be invoked by the Message Queue budget trigger
-
Prepare a ZIP archive with the function code.
Go to the
yc-telegram-bot-with-trigger-for-budget/steps/7-create-budget-queue-handler
directory and add files to thesrc_queue.zip
archive:zip src_queue.zip budget_queue_handler.go utils.go go.mod
-
Create a function:
Management consoleCLIAPI-
In the management console
, select your folder. -
Select Cloud Functions.
-
Create a function:
- Click Create function.
- Enter the function name:
budget-queue-handler
. - Click Create.
-
Create a function version:
-
Select
golang119
as the runtime environment, disable the Add files with code examples option, and click Continue. -
Specify the ZIP archive upload method and attach the
src_queue.zip
archive created in the previous step. -
Specify the entry point:
budget_queue_handler.HandleBudgetQueueMessage
. -
Under Parameters, specify:
- Timeout, sec:
5
- Memory:
512 MB
- Service account:
service-account-for-budget
- Environment variables:
TELEGRAM_BOT_API_TOKEN
: Previously saved API token of the Telegram bot.TELEGRAM_BOT_CHAT_ID
: Previously savedChatID
of the Telegram user.
- Timeout, sec:
-
Click Save changes.
-
-
Create the
budget-queue-handler
function:yc serverless function create \ --name budget-queue-handler
Result:
id: d4e6r2g9trt5******** folder_id: b1g9d2k0itu4******** created_at: "2024-02-24T07:36:04.092Z" name: budget-queue-handler http_invoke_url: https://functions.yandexcloud.net/d4e6r2g9trt5******** status: ACTIVE
-
Create a version of the
budget-queue-handler
function:yc serverless function version create \ --function-name budget-queue-handler \ --memory 512m \ --execution-timeout 5s \ --runtime golang119 \ --entrypoint budget_queue_handler.HandleBudgetQueueMessage \ --service-account-id <service_account_ID> \ --environment TELEGRAM_BOT_API_TOKEN=<Telegram_bot_API_token> \ --environment TELEGRAM_BOT_CHAT_ID=<Telegram_user_ChatID> \ --source-path="./src_queue.zip"
Where:
-
--service-account-id
: Previously saved ID of theservice-account-for-budget
service account. The service account will be used to invoke the function. -
--environment
: Environment variables:TELEGRAM_BOT_API_TOKEN
: Previously saved API token of the Telegram bot.TELEGRAM_BOT_CHAT_ID
: Previously savedChatID
of the Telegram user.
-
--source-path
: Path to thesrc_queue.zip
archive.
Result:
done (29s) id: d4e41l4gj7rk******** function_id: d4e6r2g9trt5******** created_at: "2024-02-24T07:43:32.464Z" runtime: golang119 entrypoint: budget_queue_handler.HandleBudgetQueueMessage resources: memory: "536870912" execution_timeout: 5s service_account_id: ajed1o6dd581******** image_size: "5464064" status: ACTIVE tags: - $latest environment: TELEGRAM_BOT_API_TOKEN: 7150638333:AAGujjyua-0VrIm7j9iG3mOxmz1******** TELEGRAM_BOT_CHAT_ID: "59529*****" log_options: folder_id: b1g9d2k0itu4********
-
To create a function, use the create method for the Function resource or the FunctionService/Create gRPC API call.
To create a function version, use the createVersion method for the Function resource or the FunctionService/CreateVersion gRPC API call.
-
Create a trigger for Message Queue
-
In the management console
, select your folder. -
Select Cloud Functions.
-
In the left-hand panel, select
Triggers. -
Click Create trigger.
-
Under Basic settings:
- In the Name field, specify the trigger name:
budget-queue-trigger
. - In the Type field, select
Message Queue
. - In the Launched resource field, select
Function
.
- In the Name field, specify the trigger name:
-
Under Message Queue message settings, select the previously created resources:
- In the Message queue field,
budget-queue
. - In the Service account field,
service-account-for-budget
.
- In the Message queue field,
-
Under Function settings, select the
budget-queue-handler
function and specify theservice-account-for-budget
service account. It will be used to invoke the function. -
Click Create trigger.
To create a trigger for Message Queue that invokes the budget-queue-handler
function, run the following command:
yc serverless trigger create message-queue \
--name budget-queue-trigger \
--queue <queue_ID> \
--queue-service-account-id <service_account_ID> \
--invoke-function-name budget-queue-handler \
--invoke-function-service-account-id <service_account_ID> \
--batch-size 1 \
--batch-cutoff 10s
Where:
--queue
:budget-queue
ID saved when creating the queue.--queue-service-account-id
: Previously saved ID of theservice-account-for-budget
service account. The service account will be used to read messages from the queue.--invoke-function-service-account-id
: Previously saved ID of theservice-account-for-budget
service account. The service account will be used to invoke the function.
Result:
id: a1sqq6341kvh********
folder_id: b1g9d2k0itu4********
created_at: "2024-02-24T08:35:39.296084612Z"
name: budget-queue-trigger
rule:
message_queue:
queue_id: yrn:yc:ymq:ru-central1:b1g9d2k0itu4********:budget-queue
service_account_id: ajed1o6dd581********
batch_settings:
size: "1"
cutoff: 10s
invoke_function:
function_id: d4e6r2g9trt5********
function_tag: $latest
service_account_id: ajed1o6dd581********
status: ACTIVE
For more information about the yc serverless trigger create message-queue
command, see the CLI reference.
To create a trigger for Message Queue, use the create method for the Trigger resource or the TriggerService/Create gRPC API call.
Create Compute Cloud VMs
-
In the management console
, select the folder to create your VM in. -
In the list of services, select Compute Cloud.
-
In the left-hand panel, select
Virtual machines. -
Click Create virtual machine.
-
Under Boot disk image, select Ubuntu 22.04 LTS.
-
Under Location, select the
ru-central1-b
availability zone. -
Under Network settings:
- In the Subnet field, select the
sample-subnet-ru-central1-b
subnet you created earlier. - In the Public IP field, select
Auto
.
- In the Subnet field, select the
-
Under Access, select SSH key and specify the information required to access the VM:
- In the Login field, enter a username, e.g.,
yc-user
. -
In the SSH key field, select the SSH key saved in your organization user profile.
If there are no saved SSH keys in your profile, or you want to add a new key:
- Click Add key.
- Enter a name for the SSH key.
- Upload or paste the contents of the public key file. You need to create a key pair for the SSH connection to a VM yourself.
- Click Add.
The SSH key will be added to your organization user profile.
If users cannot add SSH keys to their profiles in the organization, the added public SSH key will only be saved to the user profile of the VM being created.
- In the Login field, enter a username, e.g.,
-
Under General information:
- Specify the VM name,
target-instance-1
. - In the Labels field, click Add label and enter
target-for-stop:true
. Click Enter to save the label.
- Specify the VM name,
-
Click Create VM.
Create a virtual machine:
yc compute instance create \
--name target-instance-1 \
--labels target-for-stop=true \
--zone ru-central1-b \
--network-interface subnet-name=sample-subnet-ru-central1-b,nat-ip-version=ipv4 \
--create-boot-disk image-folder-id=standard-images,image-family=ubuntu-2204-lts \
--ssh-key ~/.ssh/<key_name>.pub
Where --ssh-key
is the path to the public SSH key The yc-user
user will be automatically created on the VM for this key.
Result:
done (39s)
id: epdbhj4gssbp********
folder_id: b1g9d2k0itu4********
created_at: "2024-02-24T09:29:16Z"
name: target-instance-1
labels:
target-for-stop: "true"
zone_id: ru-central1-b
platform_id: standard-v2
resources:
memory: "2147483648"
cores: "2"
core_fraction: "100"
status: RUNNING
metadata_options:
gce_http_endpoint: ENABLED
aws_v1_http_endpoint: ENABLED
gce_http_token: ENABLED
aws_v1_http_token: DISABLED
boot_disk:
mode: READ_WRITE
device_name: epd4uuhf52oe********
auto_delete: true
disk_id: epd4uuhf52oe********
network_interfaces:
- index: "0"
mac_address: d0:0d:b8:**:**:**
subnet_id: e2l1ejkvq4jv********
primary_v4_address:
address: 192.168.1.9
one_to_one_nat:
address: 158.160.**.***
ip_version: IPV4
serial_port_settings:
ssh_authorization: INSTANCE_METADATA
gpu_settings: {}
fqdn: epdbhj4gssbp********.auto.internal
scheduling_policy: {}
network_settings:
type: STANDARD
placement_policy: {}
For more information about the yc compute instance create
command, see the CLI reference.
To create a VM, use the create REST API method for the Instance resource or the InstanceService/Create gRPC API call.
Similarly, create two more VMs: target-instance-2
and target-instance-3
. For the last VM, set the target-for-stop
label to false
.
Make sure the trigger stops VMs and sends Telegram notifications
Wait until the threshold values that you specified in the budget are reached. Make sure that when the budget thresholds are reached, the target-instance-1
and target-instance-2
virtual machines stop, and the Telegram bot sends you a budget trigger notification:
Budget trigger was triggered!
How to delete the resources you created
To stop paying for the resources you created: