이 문서에서는 Pub/Sub를 사용하여 프로그래매틱 예산 및 비용 이상치(프리뷰) 알림을 설정하는 방법을 설명합니다.
예산 및 비용 이상치는 일반적으로 이메일 알림을 보내도록 구성됩니다. 예산 또는 비용 이상 감지를 비용 관리 도구로 사용하는 경우, 이메일 알림은 비용을 시기적절하게 제어하기에 적합한 방법이 아닐 수 있습니다.
프로그래매틱 알림을 설정하고 사용하여 비용 관리 응답을 자동화할 수 있습니다. 자동화된 비용 관리 응답의 예는 다음과 같습니다.
예산에 사용되는 Cloud Billing 데이터는 예상치이며, 이는 인보이스가 확정되기 전까지는 변경될 수 있습니다.
도메인별 리소스 공유를 제한하도록 조직 정책을 설정하면(예: Pub/Sub 주제에서 enforceInTransit 사용 설정) Pub/Sub 주제를 설정하거나 연결하려고 할 때 오류가 발생할 수 있습니다. 이 경우 Pub/Sub 주제를 예산에 성공적으로 연결하기 위해 계정 액세스를 강제해야 할 수 있습니다. 계정 액세스를 강제하려면 다음 단계를 완료하세요.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-04-21(UTC)"],[[["\u003cp\u003eThis guide teaches how to set up automated responses to Cloud Billing budget and cost anomaly notifications using Pub/Sub.\u003c/p\u003e\n"],["\u003cp\u003eYou can automate cost control responses by integrating with platforms like Slack, managing resource consumption, or even disabling billing when a budget is reached.\u003c/p\u003e\n"],["\u003cp\u003eTo set up these programmatic notifications, you'll need specific permissions for creating or modifying budgets/anomalies and Pub/Sub topics, varying based on your access level (Cloud Billing account or project).\u003c/p\u003e\n"],["\u003cp\u003eBudget notifications are sent multiple times daily via Pub/Sub with the budget's status, while anomaly notifications are sent only when a predefined cost impact threshold is met.\u003c/p\u003e\n"],["\u003cp\u003eThe tutorial covers creating a Pub/Sub topic, connecting it to budgets or anomalies, and understanding the notification format, which includes attributes and data describing the event and budget/anomaly details.\u003c/p\u003e\n"]]],[],null,["# Set up programmatic notifications\n\n\u003cbr /\u003e\n\n| #### Interactive tutorials: Set up automated responses to Cloud Billing\n| budget notifications (30 minutes)\n|\n| In this interactive tutorial, you'll learn how to do the following:\n|\n| - Set up a Pub/Sub topic\n| - Create a budget on a billing account that's connected to the Pub/Sub topic\n| - Create a Cloud Run function that listens for updates from the Pub/Sub topic\n| - Test your Cloud Run function\n|\n| [**Launch the tutorial**](https://console.cloud.google.com/home/dashboard?walkthrough_tutorial_id=billing--budget--cost_enforcement)\n\nThis document explains how to set up programmatic budget and cost anomaly\n([Preview](/products#product-launch-stages))\nnotifications using\n[Pub/Sub](/pubsub/docs/pubsub-basics).\n\n[Budgets](/billing/docs/how-to/budgets#manage-notifications)\nand [cost anomalies](/billing/docs/how-to/manage-anomalies#set-notifications)\nare typically configured to send email notifications. If you use budgets or\ncost anomaly detection as a cost control tool, email notifications might not be\nthe best method to use to ensure timely action to control your costs.\nYou can set up and use programmatic notifications to automate cost control\nresponses. Examples of automated cost control responses include the following:\n\n- [Integrate with Slack for faster response](/billing/docs/how-to/send-notifications-to-slack)\n- [Manage resource consumption to reduce costs](/billing/docs/how-to/control-usage)\n- [Limit spending by disabling billing when you reach your budget](/billing/docs/how-to/disable-billing-with-notifications)\n\nLimitations\n-----------\n\n- Budgets use estimated Cloud Billing data which is subject to\n change until your invoice is finalized.\n\n- If you set [organization policies](/resource-manager/docs/organization-policy/overview)\n to [limit resource sharing by domain](/resource-manager/docs/organization-policy/restricting-domains)\n (for example, enabling `enforceInTransit` on Pub/Sub topics),\n you might encounter an error when you try to set up or connect Pub/Sub\n topics. In this situation, you might need to\n [force account access](/resource-manager/docs/organization-policy/restricting-domains#forcing_access)\n to successfully connect a Pub/Sub topic to a budget. To force\n account access, complete the following steps:\n\n 1. Remove the organization policy containing the domain restriction constraint using one of the following methods:\n - Temporarily [remove the organization policy](/resource-manager/docs/organization-policy/using-constraints#delete_an_organization_policy).\n - [Override the organization policy for the project](/resource-manager/docs/organization-policy/using-constraints#override_the_organization_policy_for_a_project) that contains the [Pub/Sub topic](#pub-sub-topic).\n 2. Follow the steps to [connect a Pub/Sub topic](#connect-topic).\n 3. Reinstate the [organization policy](/resource-manager/docs/organization-policy/using-constraints#set_up_enforcement_on_the_organization_resource) for the organization or project (optional).\n\nPermissions required for this task\n----------------------------------\n\n### Budget notifications\n\nTo set up programmatic budget notifications, you need permissions to create or\nmodify budgets and Pub/Sub topics. You need a different set of\npermissions depending on your level of access.\n\n### Anomaly notifications\n\nTo set up programmatic anomaly notifications, you need permissions to create\nor modify anomalies and Pub/Sub topics. You must have\nCloud Billing account permissions.\n\nCreate a Pub/Sub topic\n----------------------\n\nTo set up programmatic budget or anomaly notifications, you must first\n[create a Pub/Sub topic](/pubsub/docs/create-topic).\nIf you already configured a Pub/Sub\ntopic for budgets or cost anomalies, you can skip this step.\n\n1. Go to the Google Cloud console **Pub/Sub** page.\n\n [Sign in to Google Cloud console Pub/Sub](https://console.cloud.google.com/cloudpubsub/)\n2. Select a project to contain the Pub/Sub topic.\n\n When configuring Pub/Sub topics for billing notifications, we\n recommend you use a\n [FinOps administration project](/billing/docs/how-to/create-billing-account#set-up-billing-project)\n to contain your billing-related Pub/Sub topics.\n3. Click add_box\n **Create topic**.\n\n4. In the **Topic ID** field, provide a topic name.\n\n5. Retain the default subscription and encryption settings, and click\n **Create**.\n\n| **Note:** You must have permission to grant the Pub/Sub Publisher role on the topic to allow Cloud Billing to publish messages to it.\n\nConnect your Pub/Sub topic\n--------------------------\n\nTo enable programmatic notifications to receive Pub/Sub\nmessages with the current status of your budget or anomaly, you must connect\nyour budget or anomaly to your Pub/Sub topic. \n\n### Budget notifications\n\nTo connect a Pub/Sub topic to a Cloud Billing budget,\ncomplete the following steps:\n\n### Anomaly notifications\n\nTo connect a Pub/Sub topic to a cost anomaly, complete the\nfollowing steps:\n\nNotification format\n-------------------\n\nNotifications sent to the Pub/Sub topic consist of two parts:\n\n- **Attributes**: A set of key-value pairs describing the event.\n- **Data**: A string containing a JSON object that describes the budget alert\n details.\n\n### Budget notifications\n\n### Attributes\n\nAttributes are key-value pairs contained in all notifications sent\nby Cloud Billing to your Pub/Sub topic. Notifications always\ncontain the following set of key-value pairs, regardless of the\nnotification payload.\n\n### Data\n\nBudget alert details are returned in a base64-encoded UTF-8 string containing\na JSON object with the following properties:\n\n| **Note:** To test an example budget notification, follow the steps in [Listen to your notifications](/billing/docs/how-to/listen-to-notifications).\n\n### Anomaly notifications\n\n### Attributes\n\nAttributes are key-value pairs contained in all notifications sent by\nCloud Billing to your Pub/Sub topic. Notifications always\ncontain the following set of key-value pairs, regardless of the notification\npayload.\n\n### Data\n\nAnomaly alert details are returned in a base64-encoded UTF-8 string containing\na JSON object with the following properties:\n\nDelivery guarantees for notifications to Pub/Sub\n------------------------------------------------\n\nAfter you connect your budget or anomaly to a Pub/Sub topic, you\ncan expect to receive programmatic notifications as follows: \n\n### Budget notifications\n\n- Budget notifications are sent to the Pub/Sub topic multiple times per day with the current status of your budget. This cadence is different than the cadence for budget alert emails, which are only sent when a [budget threshold](/billing/docs/how-to/budgets#alert-thresholds) is met.\n- Pub/Sub notifications are sent even if the Cloud Billing account has no usage.\n- It may take several hours before you receive the first Pub/Sub notification.\n- Pub/Sub only guarantees at-least-once delivery. You might receive a message multiple times, and messages might arrive out of order.\n- If delivery fails due to Pub/Sub topic misconfiguration, you won't be notified.\n\nDelivery might fail for one of the following reasons:\n\n- The Pub/Sub topic no longer exists.\n- The Cloud Billing no longer has permission to publish to the Pub/Sub topic.\n- You exceeded your notification quota.\n- You have [organization policies](/resource-manager/docs/organization-policy/overview) in place that [limit resource sharing by domain](/resource-manager/docs/organization-policy/restricting-domains).\n\n### Anomaly notifications\n\n- Anomaly notifications are sent to the Pub/Sub topic only when the [threshold](/billing/docs/how-to/manage-anomalies#set-anomaly-threshold) is reached.\n- Pub/Sub only guarantees an at-least-once delivery. You might receive a message multiple times, and messages might arrive out of order.\n- If delivery fails due to Pub/Sub topic misconfiguration, you won't be notified.\n\nDelivery might fail for one of the following reasons:\n\n- The Pub/Sub topic no longer exists.\n- The Cloud Billing account no longer has permission to publish to the Pub/Sub topic.\n- You exceeded your notification quota.\n- You have [organization policies](/resource-manager/docs/organization-policy/overview) in place that [limit resource sharing by domain](/resource-manager/docs/organization-policy/restricting-domains).\n\nFor more information, see\n[Publish and receive messages in Pub/Sub](/pubsub/docs/publish-receive-messages-console).\n\nWhat's next\n-----------\n\nTo learn more about how you can use programmatic notifications, review the\nfollowing examples of programmatic cost control responses:\n\n- [Listen to your notifications](/billing/docs/how-to/listen-to-notifications)\n- [Send notifications to Slack](/billing/docs/how-to/send-notifications-to-slack)\n- [Control resource usage with notifications](/billing/docs/how-to/control-usage)\n- [Disable billing usage with notifications](/billing/docs/how-to/disable-billing-with-notifications)"]]