Creating triggers that invoke Cloud Functions functions to stop a VM and send Telegram notifications
- Get your cloud ready
- Create a budget
- Create a Message Queue
- Create a Cloud Functions function the budget trigger will invoke
- Create a budget trigger
- Register your Telegram bot
- Create a Cloud Functions function the Message Queue budget trigger will invoke
- Create a trigger for Message Queue
- Create Compute Cloud VMs
- Make sure the trigger stops the VMs and sends Telegram notifications
- How to delete the resources you created
In this tutorial, you will create a serverless infrastructure that will stop the virtual machines and send Telegram notifications when the VM resource use exceeds budget thresholds.
The budget trigger will invoke the Cloud Functions function that will stop the Compute Cloud virtual machines and send a message to the Yandex Message Queue queue.
The Message Queue trigger will deliver the queued messages to the second Cloud Functions function that will send Telegram notifications via a dedicated bot.
To deploy a project:
- Get your cloud ready.
- Create a budget.
- Create a Message Queue queue.
- Create a Cloud Functions function that the budget trigger will invoke.
- Create a budget trigger.
- Register your Telegram bot.
- Create a Cloud Functions function the Message Queue trigger will invoke.
- Create a trigger for Message Queue.
- Create Compute Cloud VM instances.
- Make sure the trigger stops the VMs and sends Telegram notifications.
Create all specified Yandex Cloud resources in the same folder.
If you no longer need the resources you created, delete them.
Get your cloud ready
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can navigate to the cloud page
Learn more about clouds and folders here.
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 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 you use Cloud Logging.
Download a project
Clone the repository containing 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 theeditorrole. - Click Create.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the
yc config set folder-id <folder_ID>command. You can also set a different folder for any specific command using the--folder-nameor--folder-idparameter.-
Create a service account named
service-account-for-budget:yc iam service-account create \ --name service-account-for-budgetResult:
done (1s) id: ajed1o6dd581******** folder_id: b1g9d2k0itu4******** created_at: "2024-02-23T18:32:38.365175925Z" name: service-account-for-budgetSave the service account ID (
id): you will need it in the next step.For more information about the
yc iam service-account createcommand, see the CLI reference. -
Assign the service account the
editorrole 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>: Service account ID you saved in the previous step.
Result:
done (2s) effective_deltas: - action: ADD access_binding: role_id: editor subject: id: ajed1o6dd581******** type: serviceAccountFor more information about the
yc resource-manager folder add-access-bindingcommand, 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-budgetservice 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 this dialog, the key value will no longer be available.
Run this command:
yc iam access-key create \ --service-account-name service-account-for-budgetResult:
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). This is the only time you can copy this key as it will not be shown again.For more information about the
yc iam access-key createcommand, 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. - From 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 Availability zone field, select the
ru-central1-bavailability zone. - In the Network field, select
my-sample-network. - In the CIDR field, specify
192.168.1.0/24. - Click Create subnet.
-
Create a network named
my-sample-network:yc vpc network create my-sample-networkResult:
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 createcommand, see the CLI reference. -
Create a subnet named
sample-subnet-ru-central1-bin theru-central1-bavailability zone:yc vpc subnet create sample-subnet-ru-central1-b \ --zone ru-central1-b \ --network-name my-sample-network \ --range 192.168.1.0/24Result:
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/24For more information about the
yc vpc subnet createcommand, 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 your new queue:
budget-queue. From the window that opens, copy the field values:- 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 static access key you created in the previous step.
-
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
QueueUrlvalue; you will need it in the next steps. -
Get the queue ID by specifying the previously saved URL in the
--queue-urlparameter: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
QueueArnqueue ID; you will need it in the next steps.
Create a Cloud Functions function the budget trigger will invoke
-
Prepare a ZIP archive with the function code.
Navigate to the
yc-telegram-bot-with-trigger-for-budget/steps/4-create-budget-trigger-handlerdirectory and add files to thesrc_bgt.ziparchive: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.
- Specify the function name:
budget-trigger-handler. - Click Create.
-
Create a function version:
-
Select
golang119as 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.ziparchive you created in the previous step. -
Specify the entry point:
budget_trigger_handler.Handler. -
Under Parameters, specify:
- Timeout:
5 - Memory:
512 MB - Service account:
service-account-for-budget - Environment variables:
FOLDER_ID: ID of the folder where you want the VMs stopped.TAG:target-for-stop.AWS_ACCESS_KEY_ID: Static access key ID you saved in the previous step.AWS_ACCESS_KEY_ID: Secret key value of the static access key you saved in the previous step.BUDGET_QUEUE_URL:budget-queueURL you saved in the previous step.
- Timeout:
-
Click Save changes.
-
-
Create a function named
budget-trigger-handler:yc serverless function create \ --name budget-trigger-handlerResult:
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: ACTIVEFor more information about the
yc serverless function createcommand, see the CLI reference. -
Create a version of the
budget-trigger-handlerfunction: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=<catalog_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: ID of theservice-account-for-budgetservice account you saved in the previous step. This is the service account to invoke the function. -
--environment: Environment variables:FOLDER_ID: ID of the folder where you want the VMs stopped.AWS_ACCESS_KEY_ID: Static access key ID you saved in the previous step.AWS_ACCESS_KEY_ID: Secret key value of the static access key you saved in the previous step.BUDGET_QUEUE_URL:budget-queueURL you saved in the previous step.
-
--source-path: Path to thesrc_bgt.ziparchive.
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 createcommand, 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 budget trigger
-
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-budgetbudget you created earlier. -
Under Function settings, select the
budget-trigger-handlerfunction and specify theservice-account-for-budgetservice account. This is the service account 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: ID of theservice-account-for-budgetservice account you saved in the previous step. This is the service account to invoke the function.--billing-account-id: Billing account ID saved earlier when creating a budget.--budget-id: Budget ID you saved in the previous step.
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 your Telegram bot
-
Register a bot in Telegram and get a token:
-
To register a new bot, launch the BotFather
bot and send the following command:/newbotResult:
Alright, a new bot. How are we going to call it? Please choose a name for your bot. -
In the next message, specify the name of your bot, e.g.,
YC VM budget informer. This is the name users chatting with the bot will see.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 the username of your bot, e.g.,
YCVMBudgetInformerBot. You can use it to find the bot in Telegram. The username must end with...Botor..._bot. In response, you will receive an access 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
ChatIDof the user who will be receiving notifications from the bot:-
Save the API token you got in the previous step into the
TELEGRAM_BOT_API_TOKENenvironment variable:export TELEGRAM_BOT_API_TOKEN=<Telegram_API_token> -
Navigate to the
yc-telegram-bot-with-trigger-for-budget/steps/6-register-telegram-botdirectory and run the following command:go run .If required, pre-install the
Goandtelegram_botpackages.The command will launch a Telegram bot that will return the
ChatIDof the current user in response to any message. -
In Telegram, find your bot by its username, e.g.,
YCVMBudgetInformerBot, and send any message to it.Result:
59529*****Save the
ChatIDyou have received in response. You will need it later. -
Return to the terminal and terminate the bot by pressing Ctrl + C.
-
Create a Cloud Functions function the Message Queue budget trigger will invoke
-
Prepare a ZIP archive with the function code.
Navigate to the
yc-telegram-bot-with-trigger-for-budget/steps/7-create-budget-queue-handlerdirectory and add files to thesrc_queue.ziparchive: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.
- Specify the function name:
budget-queue-handler. - Click Create.
-
Create a function version:
-
Select
golang119as 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.ziparchive you created in the previous step. -
Specify the entry point:
budget_queue_handler.HandleBudgetQueueMessage. -
Under Parameters, specify:
- Timeout:
5 - Memory:
512 MB - Service account:
service-account-for-budget - Environment variables:
TELEGRAM_BOT_API_TOKEN: API token of the Telegram bot you saved in the previous step.TELEGRAM_BOT_CHAT_ID:ChatIDof the Telegram user you saved in the previous step.
- Timeout:
-
Click Save changes.
-
-
Create a function named
budget-queue-handler:yc serverless function create \ --name budget-queue-handlerResult:
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-handlerfunction: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: ID of theservice-account-for-budgetservice account you saved in the previous step. This is the service account to invoke the function. -
--environment: Environment variables:TELEGRAM_BOT_API_TOKEN: API token of the Telegram bot you saved in the previous step.TELEGRAM_BOT_CHAT_ID:ChatIDof the Telegram user you saved in the previous step.
-
--source-path: Path to thesrc_queue.ziparchive.
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 resources you created in the previous steps:
- In the Message queue field, select
budget-queue. - In the Service account field, select
service-account-for-budget.
- In the Message queue field, select
-
Under Function settings, select the
budget-queue-handlerfunction and specify theservice-account-for-budgetservice account. This is the service account 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-queueID you saved when creating the queue.--queue-service-account-id: ID of theservice-account-for-budgetservice account you saved in the previous step. The system will use the service account to read messages from the queue.--invoke-function-service-account-id: ID of theservice-account-for-budgetservice account you saved in the previous step. This is the service account 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 where you want to create your VM. -
From 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-bavailability zone. -
Under Network settings:
- In the Subnet field, select
sample-subnet-ru-central1-b. - In the Public IP address field, select
Auto.
- In the Subnet field, select
-
Under Access, select SSH key and specify the VM access credentials:
- In the Login field, specify 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 SSH keys in your profile or you want to add a new key:
-
Click Add key.
-
Enter a name for the SSH key.
-
Select one of the following:
-
Enter manually: Paste the contents of the public SSH key. You need to create an SSH key pair on your own. -
Load from file: Upload the public part of the SSH key. You need to create an SSH key pair on your own. -
Generate key: Automatically create an SSH key pair.When adding a new SSH key, an archive containing the key pair will be created and downloaded. In Linux or macOS-based operating systems, unpack the archive to the
/home/<user_name>/.sshdirectory. In Windows, unpack the archive to theC:\Users\<user_name>/.sshdirectory. You do not need additionally enter the public key in the management console.
-
-
Click Add.
The system will add the SSH key to your organization user profile. If the organization has disabled the ability for users to add SSH keys to their profiles, the added public SSH key will only be saved in the user profile inside the newly created resource.
-
- In the Login field, specify 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 VM will automatically create the user called yc-user 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 latter, set the target-for-stop label to false.
Make sure the trigger stops the VMs and sends Telegram notifications
Wait until the resource use of your VMs reaches the threshold values specified in your budget. Make sure that, when it happens, 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: