Tutorial: Getting started with Budgets¶
Introduction¶
This tutorial introduces you to account-level credit usage monitoring with Budgets by setting up the account budget and creating a custom budget that monitors a group of specified objects.
With budgets, you can monitor credit usage for the compute costs of supported objects, including credit usage for background maintenance tasks and serverless features. Budgets enables you to set a monthly spending limit for each budget and sends a notification email when your current spending is projected to exceed the monthly spending limit.
You can complete this tutorial using a worksheet in Snowsight or using a CLI client such as SnowSQL. Some portions of this tutorial can be completed using Snowsight.
By the end of this tutorial, you will learn how to to do the following:
Create custom roles to monitor and manage budgets.
Grant the required privileges to add objects to a custom budget.
Activate and set up an account budget.
Create a custom budget and add objects to it.
Prerequisites¶
To complete this tutorial, the following prerequisites are required:
You must be able to use the ACCOUNTADMIN role to create the roles used in this tutorial.
You must verify your email address. Only verified email addresses can be added to a budget notification list.
Create a notification integration¶
Budgets use a notification integration to send notification emails when current credit usage is expected to exceed the monthly
spending limit. The ALLOWED_RECIPIENTS
list must include the verified email addresses
of the users to receive budgets notifications.
A notification integration is required if you are completing the tutorial using SQL. Follow the steps below to create one.
When you use Snowsight to set up a budget, the notification integration is automatically created for you. If you are going to use Snowsight to set up your budgets, you can skip to the next step.
Execute the following statement to create a notification integration. Use your verified email address in the ALLOWED_RECIPIENTS list:
CREATE NOTIFICATION INTEGRATION budgets_notification_integration TYPE=EMAIL ENABLED=TRUE ALLOWED_RECIPIENTS=('<YOUR_EMAIL_ADDRESS>');
After you create the notification integration, grant the USAGE privilege to the SNOWFLAKE application. This privilege is required in order for Budgets to use the notification integration to send emails.
Execute the following statement to grant the USAGE privilege on the notification integration:
GRANT USAGE ON INTEGRATION budgets_notification_integration TO APPLICATION snowflake;
Create custom roles to manage, monitor, and create budgets¶
In this step, the following objects are created for the tutorial:
A custom role to manage the account budget.
A custom role to monitor the account budget.
A custom role to create custom budgets.
Create custom roles to manage, monitor, and create budgets¶
Create custom role
account_budget_admin
for the account budget administrator. The account budget administrator can take the following actions on the account budget:Activate and deactivate the account budget.
Set the spending limit.
Edit notification settings.
Monitor credit usage for the account.
USE ROLE ACCOUNTADMIN; CREATE ROLE account_budget_admin; GRANT APPLICATION ROLE SNOWFLAKE.BUDGET_ADMIN TO ROLE account_budget_admin; GRANT IMPORTED PRIVILEGES ON DATABASE SNOWFLAKE TO ROLE account_budget_admin;
Create custom role
account_budget_monitor
to be granted to account budget monitors. An account budget monitor can take the following actions on the account budget:Monitor credit usage for the account.
View the email notification settings.
View the monthly spending limit for the account.
USE ROLE ACCOUNTADMIN; CREATE ROLE account_budget_monitor; GRANT APPLICATION ROLE SNOWFLAKE.BUDGET_VIEWER TO ROLE account_budget_monitor; GRANT IMPORTED PRIVILEGES ON DATABASE SNOWFLAKE TO ROLE account_budget_monitor;
Create a custom role
custom_budget_owner
with the required role and privileges to create custom budgets in the schemabudgets_db.budgets_schema
:USE ROLE ACCOUNTADMIN; CREATE ROLE budget_owner; GRANT USAGE ON DATABASE budgets_db TO ROLE budget_owner; GRANT USAGE ON SCHEMA budgets_db.budgets_schema TO ROLE budget_owner; GRANT DATABASE ROLE SNOWFLAKE.BUDGET_CREATOR TO ROLE budget_owner; GRANT CREATE SNOWFLAKE.CORE.BUDGET ON SCHEMA budgets_db.budgets_schema TO ROLE budget_owner;
Grant the
account_budget_admin
andcustom_budget_owner
roles to yourself to use in the next steps of the tutorial using the following steps:Grant the
account_budget_admin
role to yourself:GRANT ROLE account_budget_admin TO USER <USER_NAME>;
Grant the
custom_budget_owner
role to yourself:GRANT ROLE custom_budget_owner TO USER <USER_NAME>;
Grant the
account_budget_admin
andcustom_budget_owner
roles to yourself:Sign in to Snowsight.
Switch to the ACCOUNTADMIN role.
In the navigation menu, select Admin » Users & Roles, and then select Roles.
Select Table and locate and select the role
account_budget_admin
.In the section 0 users have been granted ACCOUNT_BUDGET_ADMIN, select Grant to User.
For User to receive grant, select your username to grant the role to.
Select Grant.
After the role is granted, return to the previous page.
Select the role custom_budget_owner.
In the section 0 users have been granted CUSTOM_BUDGET_OWNER, select Grant to User.
For User to receive grant, select your username to grant the role to.
Select Grant.
Create two custom roles to manage and monitor custom budgets. These roles will be granted privileges later in the tutorial after the custom budget is created.
You can create new roles using the following steps:
Create two custom roles for managing and monitoring custom budgets:
USE ROLE accountadmin; CREATE ROLE budget_admin; CREATE ROLE budget_monitor;
Create two custom roles for managing and monitoring custom budgets:
Sign in to Snowsight.
Switch to the ACCOUNTADMIN role.
In the navigation menu, select Admin » Users & Roles, and then select Roles.
Select + Role.
In the Name field, enter
budget_admin
.Select Create.
After the role is created, select + Role again.
In the Name field, enter
budget_monitor
.Select Create.
In this section, you created custom roles to manage and monitor budgets, and create custom budgets.
Create the objects for the custom budget¶
In this step, create objects to add to a custom budget and grant privileges to the custom roles you created in the previous step. You will be creating the following objects:
A warehouse to add to a custom budget.
A database to add to a custom budget.
A database and schema to contain the custom budget.
Create a warehouse and grant the APPLYBUDGET privilege on the warehouse to the custom budget owner role you created. The APPLYBUDGET privilege is required to add an object to a budget.
Create warehouse
na_finance_wh
:CREATE WAREHOUSE na_finance_wh;
Grant the APPLYBUDGET privilege on the warehouse to role
custom_budget_owner
:GRANT APPLYBUDGET ON WAREHOUSE na_finance_wh TO ROLE custom_budget_owner;
Create warehouse
na_finance_wh
:Sign in to Snowsight.
Select Admin » Warehouses » + Warehouse
In the Warehouse Name field, enter
na_finance_wh
.Select Create Warehouse.
Grant the APPLYBUDGET privilege on the warehouse to role
custom_budget_owner
:Select Admin » Warehouses.
Select warehouse you just created
na_finance_wh
.In the Privileges tile, select + Privilege.
For the Role, select the
custom_budget_owner
role.For the Privilege, select APPLYBUDGET.
Select Grant Privileges.
Create a database and grant the APPLYBUDGET privilege on the warehouse to the custom budget owner role you created. The APPLYBUDGET privilege is required to add an object to a budget.
Create a database:
CREATE DATABASE na_finance_db;
Grant the APPLYBUDGET privilege on the database to role
custom_budget_owner
:GRANT APPLYBUDGET ON DATABASE na_finance_db TO ROLE custom_budget_owner;
Create a database:
Sign in to Snowsight.
Select Data » Databases » + Database
In the Name field, enter
na_finance_db
.Select Create.
Grant the APPLYBUDGET privilege on the database to role
custom_budget_owner
:Select Data » Databases.
Select the database you just created
na_finance_db
.In the Privileges tile, select + Privilege.
For the Role, select the
custom_budget_owner
role.For the Privilege, select APPLYBUDGET.
Select Grant Privileges.
Create a database and schema in which to create a custom budget using the following steps:
Create the database and schema in which to create the custom budget:
CREATE DATABASE budgets_db; CREATE SCHEMA budgets_db.budgets_schema;
After you create the database and schema for the custom budget, grant the USAGE privilege on the database you just created to the role
custom_budget_owner
. The USAGE privilege is required to enable the role to create a budget in the database:GRANT USAGE ON DATABASE budgets_db TO ROLE custom_budget_owner;
Now grant the USAGE privilege on the schema you just created to the role
custom_budget_owner
. The USAGE privilege is required to enable the role to create a budget in the database:GRANT USAGE ON SCHEMA budgets_db.budgets_schema TO ROLE custom_budget_owner;
Create the database and schema in which to create the custom budget:
Sign in to Snowsight.
Select Data » Databases » + Database.
In the Name field, enter
budgets_db
.Select Create.
After the database is created, select the
budgets_tutorial_db
.Select Schemas » + Schema.
In the Name field, enter
budgets_schema
.Select Create.
After you create the database and schema for the custom budget, grant the USAGE privilege on the database you just created to the role
custom_budget_owner
. The USAGE privilege is required to enable the role to create a budget in the database:Select Data » Databases.
Select the database you just created
budgets_db
.In the Privileges tile, select + Privilege.
For the Role, select the
custom_budget_owner
role.For the Privilege, select USAGE.
Select Grant Privileges.
Now grant the USAGE privilege on the schema you just created to the role
custom_budget_owner
. The USAGE privilege is required to enable the role to create a budget in the database:Select Data » Databases.
Select database
budgets_db
» schemabudgets_schema
.In the Privileges tile, select + Privilege.
For the Role, select the
custom_budget_owner
role.For the Privilege, select USAGE.
Select Grant Privileges.
In this section, you created the objects to be added to a custom budget and granted the APPLYBUDGET privilege required to add those objects to a budget. You also created the database and schema in which to create the custom budget and granted the USAGE privilege required to create a budget in the schema. Now you are ready to activate, create, and set up budgets.
Activate and set up the account budget¶
The account budget monitors credit usage for the compute costs of all Budgets supported objects in the account, including background maintenance tasks (for example, automatic clustering) and serverless features. The account budget must be activated before it can start monitoring credit usage. After it is activated, you can set the monthly spending limit for the account and the email list of notification recipients. Budgets sends a notification email when current credit usage is expected to exceed the monthly spending limit.
Activate and set up the account budget using the following steps:
Use the
account_budget_admin
role you created in a previous step to activate the account budget:USE ROLE account_budget_admin; CALL snowflake.local.account_root_budget!ACTIVATE();
Set the spending limit for the account budget to 500 credits per month:
CALL snowflake.local.account_root_budget!SET_SPENDING_LIMIT(500);
To set up the email notification list, use your verified email address and the notification integration you created earlier in the tutorial:
CALL snowflake.local.account_root_budget!SET_EMAIL_NOTIFICATIONS( 'budgets_notification_integration', '<YOUR_EMAIL_ADDRESS>');
Actvate and set up the account budget:
Sign in to Snowsight.
Select the ACCOUNT_BUDGET_ADMIN role you created in a previous step.
Select Admin » Cost Management.
Select Budgets.
If prompted, select
na_finance_wh
for the warehouse.In the upper-right corner of the dashboard, select Set up Account Budget.
Enter 500 for the spending limit for the account.
To help you set your monthly spending limit, the configuration tool displays your projected spend for the month and your average monthly spend for the previous 3 months. For example, see the screenshot below.
Enter your email address to receive notification emails.
Select Finish Setup.
In this section, you activated the account budget and set the spending limit and the email address to receive budget notifications.
Create a custom budget¶
Now that you have activated and set up your account budget, create a custom budget to monitor the credit usage
in your account for a specified group of objects. For this tutorial, add the na_finance_wh
warehouse and
na_finance_db
to the custom budget.
Create custom budgets with the following steps:
Use the
custom_budget_owner
role to create budgetna_finance_budget
inbudgets_db.budgets_schema
:USE ROLE custom_budget_owner; USE SCHEMA budgets_db.budgets_schema; CREATE SNOWFLAKE.CORE.BUDGET na_finance_budget();
Set the monthly spending limit to 500 credits:
CALL na_finance_budget!SET_SPENDING_LIMIT(500);
To set up the notification list, use your verified email address and the notification integration created in the first step of the tutorial:
CALL na_finance_budget!SET_EMAIL_NOTIFICATIONS('budgets_notification_integration', '<YOUR_EMAIL_ADDRESS>');
Add database
na_finance_db
and warehousena_finance_wh
to budgetna_finance_budget
:USE SCHEMA budgets_db.budgets_schema; CALL na_finance_budget!ADD_RESOURCE( SYSTEM$REFERENCE('database', 'na_finance_db', 'SESSION', 'applybudget')); CALL na_finance_budget!ADD_RESOURCE( SYSTEM$REFERENCE('warehouse', 'na_finance_wh', 'SESSION', 'applybudget'));
Use the custom_budget_owner
role to create budget na_finance_budget
:
Sign in to Snowsight.
Select the CUSTOM_BUDGET_OWNER role you created in a previous step.
Select Admin » Cost Management.
Select Budgets.
In the upper-right corner of the dashboard, select (Add Budget).
In the Budget name field, enter
na_finance_budget
.Select the database
budgets_db
and schemabudgets_schema
.Enter 500 for the Spending limit.
Enter your email address to receive notification emails.
Select Resources to monitor.
Note
You can only add an object to one custom budget. If an object is currently included in one custom budget and you add that object to a second custom budget, Budgets removes the object from the first custom budget without issuing a warning.
To add a database, expand Databases to select a database. Select
na_finance_db
.When you select a database, all the Budgets supported objects the database contains are also selected. Additionally, any future objects created in the database are automatically added to the budget.
To add a warehouse, expand Warehouses to select a warehouse. Select
na_finance_wh
.
Select Create Budget.
The Create Budget button is activated only when all the fields are completed.
In this section, you created a custom budget, added objects for the budget to monitor, and set up the email address to receive budget notifications.
Create custom roles to monitor and manage the custom budget¶
After you create the na_finance_budget
budget, you can grant privileges on the budget to the custom roles
you created in a previous step to manage and monitor the budget. These roles can be granted to users and roles to
enable users who do not have the OWNERSHIP privilege on the budget to make changes to budget settings, or monitor
credit usage, or both.
Grant privileges to the budget admin role¶
The budget admin role enables a user to take the following actions on a custom budget:
Modify the spending limit.
Modify the list of notification email recipients.
Monitor credit usage and view budget details.
Add or remove objects from the budget.
Mute or unmute notifications emails.
Use the budget owner role to grant the custom role
budget_admin
the ability to monitor the budgetna_finance_budget
in schemabudgets_db.budgets_schema
:USE ROLE custom_budget_owner; GRANT USAGE ON DATABASE budgets_db TO ROLE budget_admin; GRANT USAGE ON SCHEMA budget_db.budgets_schema TO ROLE budget_admin; GRANT SNOWFLAKE.CORE.BUDGET ROLE budgets_db.budgets_schema.na_finance_budget!ADMIN TO ROLE budget_admin; GRANT IMPORTED PRIVILEGES ON DATABASE SNOWFLAKE TO ROLE budget_admin;
Grant privileges to the budget monitor role¶
The budget monitor role enables a user to take the following actions on a custom budget:
View the list of objects in the budget.
View email notification settings.
Monitor credit usage.
Use the budget owner role to grant the custom role
budget_monitor
the ability to monitor the budgetna_finance_budget
in schemabudgets_db.budgets_schema
:USE ROLE custom_budget_owner; GRANT USAGE ON DATABASE budgets_db TO ROLE budget_monitor; GRANT USAGE ON SCHEMA budget_db.budgets_schema TO ROLE budget_monitor; GRANT SNOWFLAKE.CORE.BUDGET ROLE budgets_db.budgets_schema.na_finance_budget!VIEWER TO ROLE budget_monitor; GRANT IMPORTED PRIVILEGES ON DATABASE SNOWFLAKE TO ROLE budget_monitor;
In this section, you granted privileges to custom roles to enable them to manage or monitor the credit usage for a custom budget.
Monitoring credit usage¶
You have completed all the steps in the tutorial to activate your account budget, create a custom budget, and create custom roles to monitor and manage both account and custom budgets. Credit usage data for your budgets takes some time to populate.
Budgets uses serverless tasks to collect credit usage data for the budgets in your account. After you activate the account budget or create a custom budget, it takes a while for the serverless task to execute. After credit usage data becomes available, you can monitor credit usage for budgets using Snowsight.
Clean up, summary, and additional resources¶
Congratulations! You have successfully completed this tutorial.
After credit usage data is populated for your account budget and custom budget, see Monitoring budgets using Snowsight.
Summary and key points¶
In summary, you learned how to:
Create custom roles to manage and monitor budgets.
Custome roles enable non-account administrators to monitor credit usage for a budget and modify budget settings. For more information, see Budgets roles and privileges.
Grant the required privileges to add objects to a custom budget.
The APPLYBUDGET privilege must be granted on an object to add or remove it from a custom budget. Objects are added or removed by reference. For more information, see Adding and removing objects from a custom budget.
Activate and set up the account budget.
The account budget must be activated and set up to start monitoring credit usage for your account. The account budget monitors compute costs including background maintenance tasks and serverless features and sends an email notification when current spending is expected to exceed the monthly spending limit.
For more information, see Activating the account budget.
For a list of supported objects and the serverless features monitored by Budgets, see Supported objects and Supported serverless features.
Create a custom budget to monitor a specified group of objects in your account.
Custom budgets monitor credit usage for a group of objects in your account. Custom budgets monitor credit usage for compute costs for the objects in the group including background maintenance tasks and serverless features.
For more information, see Creating a custom budget.
For a list of supported objects and the serverless features monitored by custom budgets, see Supported objects and Supported serverless features.
Delete objects created in the tutorial¶
You can choose to keep the custom roles and custom budget you created in the tutorial to monitor credit usage. Otherwise, drop the budget and the related custom roles:
To delete the custom budget created in the tutorial, execute the following statement:
USE ROLE custom_budget_owner;
DROP SNOWFLAKE.CORE.BUDGET budgets_db.budgets_schema.na_finance_budget;
To delete the custom roles created for managing and monitoring the custom budget, execute the following statements:
USE ROLE accountadmin;
DROP ROLE custom_budget_monitor;
DROP ROLE custom_budget_admin;
DROP ROLE custom_budget owner;
Snowflake recommends leaving the account budget activated. However, if you decide to deactivate it, see Deactivating the account budget for more information and instructions.
To delete the account budget monitor and administrator roles, execute the following statements:
USE ROLE accountadmin;
DROP ROLE account_budget_monitor;
DROP ROLE account_budget_admin;
Additional resources¶
Continue learning about budgets and Snowflake using the following resources: