How do I set a cost limit in Google Developers Console

限于喜欢 提交于 2019-11-28 21:11:08

You cannot. I asked Google about this, here's their response, from May 7 2016:

(GCE = Google cloud engine. No spending limits.
GAE = Google app engine — yes it has spending limits.)

... you are eligible for support on ... only ...
... [various helpful links] ...

That been said, at the moment there is no a feature that allows you to configure a limited budget on GCE. This feature is certainly available for GAE [1]. As you mentioned in your comments, you either can totally shut down your VMs (will depend on your use case) or set the VMs to send you alerts if they reach a certain traffic limit [2].

Sincerely,

Someone's first name
Technical Solutions Representative
Google Cloud Platform

[1] https://cloud.google.com/appengine/docs/quotas
[2] https://cloud.google.com/monitoring/support/notification-options

@wmdry, you wrote: "traffic to this link could explode" — I'm afraid of this too. That's why I asked Google about this. And I'm planning to avoid Google's CDN because of this, and use another CDN provider instead, which has spending limits. Because, unlike Nginx, I don't see any way for me to rate limit / throttle Google's CDN.

I do plan to use GCE (Google Cloud Engine) though. Therefore, right now I'm reading about how to rate limit my Nginx server. Because if I just configure Nginx correctly, then those $0.12 / GB you mentioned, cannot possible explode to ... like $10k in a month? What if Google sends a $10k bill when I'm back from an a few week's vacation, just because of my hobby project and a few people downloading a 1 MB movie over and over again forever (because: evil). Hmm, & the bigger & faster my servers, the higher the risk.

I hope Google will add spending limits, because I did want to use Google's CDN.

Simply go to the developer console:

https://console.developers.google.com/project

  • Select your project.
  • Select "billings & settings"
  • Enable billing.

Then go to Compute/AppEngine/Settings and set a daily budget.

ptmr.io

As of July 2017 you can set budgets that send notifications via email but do not cap spending:

To set an alert-only budget, which will not cap spending:

  1. Go to the Cloud Platform Console.
  2. Open the console left side menu and click Billing
  3. If you have more than one billing account, click the billing account name.
  4. On the left, click Budgets & alerts.

Official help page: https://support.google.com/cloud/answer/6293540?hl=en

The API usage can be limited with a hard limit :

Depending on the API, you can explicitly cap requests in a variety of ways, including: requests per day, requests per 100 seconds, and requests per 100 seconds per user. You might want to limit the billable usage by setting caps. For example, to prevent getting billed for usage beyond the free courtesy usage limits, you can set requests per day caps

From : https://cloud.google.com/apis/docs/capping-api-usage

I found that Google's documentation now provides two methods to actually limit the cost of a GCP project. It involves the following setup:

  1. Create a Cloud Function that checks the cost against the budget, and carries out a certain action if the cost exceeds the budget. Google's Documentation provides a sample code snip that can either shutdown all VM instances in a Project or disable the billing for a project. Shutting down all VMs would stop all VM-related cost but you get to keep your data (and still have to pay for the storage). Disabling the billing for a project would effectively zap all cost-related activities and you could lose data. You can name the Cloud Function "budget-enforcer".
  2. The Google code snip as provided above has a hard coded ZONE variable. Remember to change it to match your zone!
  3. Create a Service Account to run the Cloud Function "budget-enforcer". For shutting down VMs, the Service Account would need role "Compute Instance Admin (v1)". For disabling billing on a project, the Service Account would need role "Project Billing Manager".
  4. Set a Topic for the Cloud Function (I call mine "proj-name-stop-vm" and "proj-name-disable-bill").
  5. Set up a budget alert as usual, and connect it to one of the Pub/Sub topic above.

Please be noted that Google's documentation did mention that there could be a delay between the cost exceeds a budget and the function is triggered, so you should build in a buffer if you have an absolute hard cost limit. I use 90% of the budget as the trigger line for shutting down my instances.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!