name: setup-deploy description: "Deploy AI Cost Dashboard stored procedures and Streamlit app to Snowflake." parent_skill: ai-cost-dashboard
Setup / Deploy AI Cost Dashboard
When to Load
From ai-cost-dashboard SKILL.md when user selects Setup / Deploy intent.
Prerequisites
- Snowflake connection is active
- ACCOUNTADMIN role or role with ACCOUNT_USAGE access
- Source files available at
cortex_ai_cost_dashboard/
Configurable Parameters
All object names are configurable. The source files use template placeholders ({{DATABASE}}, {{SCHEMA}}, {{WAREHOUSE}}). The deploy process resolves these before execution.
Workflow
Step 1: Configure Deployment Parameters
Goal: Collect or confirm all deployment targets.
Actions:
Ask user using
ask_user_questionwith all parameters in a single call:- Connection name (text, default: current connection)
- Database (text, default: "ADMIN_DB")
- Schema (text, default: "AI_COSTS")
- Warehouse (text, default: "COMPUTE_WH")
- Role (text, default: "ACCOUNTADMIN")
- Credit rate — the customer's current standard $/credit (text, default: "2.88")
- Historical credit rate — the customer's previous $/credit before current rate (text, default: "3.01")
Store as
CONNECTION,DATABASE,SCHEMA,WAREHOUSE,ROLE,CREDIT_RATE,HISTORICAL_CREDIT_RATE.
Output: Confirmed deployment parameters
Step 2: Resolve Templates and Run Setup SQL
Goal: Create database, schema, tables, stored procedures, rate tables, and daily task.
Actions:
Read
cortex_ai_cost_dashboard/setup.sqlResolve the
{{WAREHOUSE}}placeholder with user's warehouse valueUpdate
{{CREDIT_RATE}}with user's current credit rate and{{HISTORICAL_CREDIT_RATE}}with their historical rateWrite resolved SQL to
/tmp/ai_cost_dashboard_deploy/setup.sqlPresent deployment plan:
Will create in <DATABASE>.<SCHEMA>: - 15+ tables (CORTEX_AI_UNIFIED_COSTS, USER_AI_COSTS, + detail tables) - 2 stored procedures (REFRESH_CORTEX_AI_COSTS, REFRESH_USER_AI_COSTS) - 1 scheduled task (REFRESH_CORTEX_AI_COSTS_DAILY - 6AM UTC daily) - Credit rate tables (current: $<CREDIT_RATE>/credit, historical: $<HISTORICAL_CREDIT_RATE>/credit) - Initial data load: 365 daysSTOP: Get user approval before executing.
Execute via bash:
snow sql -f /tmp/ai_cost_dashboard_deploy/setup.sql \ --connection <CONNECTION> --role <ROLE> \ --warehouse <WAREHOUSE> --database <DATABASE> --schema <SCHEMA>Verify:
SELECT TABLE_NAME, ROW_COUNT FROM <DATABASE>.INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '<SCHEMA>' ORDER BY TABLE_NAME;
If errors occur:
- ACCOUNT_USAGE access denied -> User needs ACCOUNTADMIN or IMPORTED PRIVILEGES on SNOWFLAKE db
- Table/procedure creation fails -> Check role permissions on target database
Output: Created database objects
Step 3: Deploy Streamlit App
Goal: Deploy the Streamlit app to Snowflake.
Actions:
Resolve
cortex_ai_cost_dashboard/snowflake.yml— replace{{DATABASE}}→<DATABASE>,{{SCHEMA}}→<SCHEMA>,{{WAREHOUSE}}→<WAREHOUSE>. Write back in-place (will restore after deploy).Create stage:
USE SCHEMA <DATABASE>.<SCHEMA>; CREATE STAGE IF NOT EXISTS STREAMLIT_STAGE;Deploy via bash from the project directory:
snow streamlit deploy --connection <CONNECTION> --replaceRestore snowflake.yml to its template version (with
{{}}placeholders).Verify:
SHOW STREAMLITS LIKE 'CORTEX_AI_COST_DASHBOARD' IN SCHEMA <DATABASE>.<SCHEMA>;
Output: Deployed Streamlit app
Step 4: Upload Semantic Model
Goal: Upload resolved semantic model YAML to stage.
Actions:
Resolve
cortex_ai_cost_dashboard/cortex_ai_costs_model.yaml— replace{{DATABASE}}→<DATABASE>,{{SCHEMA}}→<SCHEMA>. Write to/tmp/ai_cost_dashboard_deploy/cortex_ai_costs_model.yaml.Upload via bash:
snow stage copy /tmp/ai_cost_dashboard_deploy/cortex_ai_costs_model.yaml \ @<DATABASE>.<SCHEMA>.STREAMLIT_STAGE --connection <CONNECTION> --overwrite
Output: Semantic model on stage
Step 5: End-to-End Validation
Goal: Confirm everything works together.
Actions:
Test stored procedures:
CALL <DATABASE>.<SCHEMA>.REFRESH_CORTEX_AI_COSTS(7); CALL <DATABASE>.<SCHEMA>.REFRESH_USER_AI_COSTS(7);Check task status:
SHOW TASKS LIKE 'REFRESH_CORTEX_AI_COSTS_DAILY' IN SCHEMA <DATABASE>.<SCHEMA>;Ask user if they want to resume the task.
Cleanup:
rm -rf /tmp/ai_cost_dashboard_deployPresent summary:
Deployment complete: - Database/Schema: <DATABASE>.<SCHEMA> - Warehouse: <WAREHOUSE> - Credit Rate: $<CREDIT_RATE>/credit (current), $<HISTORICAL_CREDIT_RATE>/credit (historical) - Tables: created and populated - Procedures: REFRESH_CORTEX_AI_COSTS, REFRESH_USER_AI_COSTS - Task: REFRESH_CORTEX_AI_COSTS_DAILY (suspended/resumed) - Streamlit: <DATABASE>.<SCHEMA>.CORTEX_AI_COST_DASHBOARD - Semantic Model: @<DATABASE>.<SCHEMA>.STREAMLIT_STAGE/cortex_ai_costs_model.yaml
Output: Validated deployment
Stopping Points
- After Step 2 plan: Before executing setup SQL
- After Step 3 plan: Before deploying Streamlit app
Output
Fully deployed AI Cost Dashboard with all objects in user-specified <DATABASE>.<SCHEMA>.