[[["わかりやすい","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-08-19 UTC。"],[[["\u003cp\u003eApp Engine costs are based on resource usage beyond the free quotas and scale with application traffic.\u003c/p\u003e\n"],["\u003cp\u003eTo control App Engine costs, users can limit the maximum number of instances via the \u003ccode\u003emax_instances\u003c/code\u003e setting in the \u003ccode\u003eapp.yaml\u003c/code\u003e file, although App Engine may briefly exceed this limit.\u003c/p\u003e\n"],["\u003cp\u003eBudget alerts can notify you when costs reach a specified threshold, and you can tailor alerts specifically for App Engine costs.\u003c/p\u003e\n"],["\u003cp\u003eManually or programmatically disabling your app can stop serving and halt associated billing charges, but other Google Cloud product costs may continue.\u003c/p\u003e\n"],["\u003cp\u003eProgrammatically disabling an app involves creating a budget alert, setting up a Pub/Sub topic, and using a Cloud Run function to disable the app automatically when the cost threshold is exceeded.\u003c/p\u003e\n"]]],[],null,["# Manage App Engine costs\n\nWith App Engine, you only pay for the resources that you use beyond the\n[free quotas](/appengine/docs/standard/quotas). After you exceed the free quotas, your costs\nscale with the amount of traffic that your application receives.\n\nTo limit the costs of your App Engine app, you can use any of the\nfollowing mechanisms:\n\n- Specify the maximum number of instances\n- Create budget alerts\n- Disable your app manually\n- Disable your app programmatically\n\nSpecify the maximum number of instances\n---------------------------------------\n\nSince App Engine costs usually scale based on the amount of traffic your\napp receives, you can limit your costs by limiting the\n[number of instances](/appengine/docs/standard/how-instances-are-managed)\nApp Engine can create.\n\nSetting the maximum to 1 instance usually keeps your instance hour usage within\nthe free tier. However, **setting the maximum too low may prevent your app from\nhaving enough instances to adequately serve incoming requests**.\n\nTo specify the maximum number of instances, use the [`max_instances`\nsetting](/appengine/docs/standard/reference/app-yaml#scaling_elements)\nin your app's `app.yaml` file.\n| **Important:** App Engine applies the `max_instances` setting on a best effort basis. **In some circumstances, App Engine may briefly exceed the limit\n| you specify.**\n\nCreate budget alerts\n--------------------\n\nBudget alerts send a notification when your costs rise above a threshold you\nspecify. When you receive a notification, you can limit costs by lowering the\nvalue of the `max_instances` setting or [disabling your app](#disable_manually).\n\nTo get started with budget alerts, see [Set budget alerts](/billing/docs/how-to/budgets).\n\n### Select the scope of a budget alert\n\nYou can create budget alerts for the total cost of all Google Cloud services\nin one or more projects, or just for the cost of App Engine.\n\nTo create a budget alert just for costs from\nApp Engine, in the Budget alert's Products field, select **App Engine**.\nThe alert will trigger when the total cost from all App Engine resources\nexceed the amount you specify, including:\n\n- Instance hours in the App Engine standard environment\n- Instance hours and RAM in the App Engine flexible environment\n- Bundled App Engine services\n\nFor the full list of billable App Engine resources, see\n[App Engine SKUs](/skus?filter=App+Engine).\n\nDisable your app manually\n-------------------------\n\nDisabling your app temporarily stops it from serving and incurring billing\ncharges related to serving your app. All of your app's data and configuration\nsettings remain unchanged, and when you are ready to start running your app\nagain, you can enable it.\n\nWhile the app is disabled, requests to your app will fail. You may continue to\nincur charges from other Google Cloud products. For example, if your project\nhas exceeded the [free quota for\nCloud Storage](/appengine/docs/standard/quotas#Default_Gcs_Bucket), you will continue\nto incur charges for storage.\n\nFor more information, see\n[Disable an app](/appengine/docs/standard/managing-projects-apps-billing#disabling_an_application).\n\nDisable your app programmatically\n---------------------------------\n\nYou can use Budget Alerts, Pub/Sub, and Cloud Run functions to\nautomatically disable your app when your costs exceed a threshold you specify.\n\nAs with manually disabling an app:\n\n- All of your app's data and configuration settings remain unchanged.\n- When you are ready to start running your app again, you can enable it.\n- Requests to your app will fail while the app is disabled.\n- You may continue to incur charges from other Google Cloud products while your app is disabled.\n\n| **Important:** With this programmatic approach, you may pay more than the amount you specify in your budget alert. Because of the delay between the time a resource is used and the time it is billed, additional costs may be incurred before all services are stopped.\n\nTo programmatically disable your app:\n\n1. Create a budget alert that sends a notification to a Pub/Sub\n topic. For details, see [Manage programmatic\n notifications](/billing/docs/how-to/budgets#manage-notifications).\n\n To create a budget alert just for costs from App Engine, in the\n Budget's Products field, select **App Engine** . For information about the\n resources that can trigger this alert, see\n [Create budget alerts](#alert_triggers).\n2. In Cloud Run functions create a function that is triggered by the\n Pub/Sub topic. For details, see [Create a Cloud\n Function](/billing/docs/how-to/notify#create_a_cloud_function).\n\n When creating the function:\n 1. Use the following source code:\n\n | **Note:** The source code assumes that the function you are creating and the app you want to disable are in the same Google Cloud project. If the function and the app are in **separate projects** , change the source code so \u003cvar translate=\"no\"\u003eAPP_NAME\u003c/var\u003e **identifies the project that contains the\n app you want to disable**. \n\n import base64\n import json\n import os\n from googleapiclient import discovery\n APP_NAME = os.getenv(\"GCP_PROJECT\")\n\n\n def limit_use_appengine(data, context):\n pubsub_data = base64.b64decode(data[\"data\"]).decode(\"utf-8\")\n pubsub_json = json.loads(pubsub_data)\n cost_amount = pubsub_json[\"costAmount\"]\n budget_amount = pubsub_json[\"budgetAmount\"]\n if cost_amount \u003c= budget_amount:\n print(f\"No action necessary. (Current cost: {cost_amount})\")\n return\n\n appengine = discovery.build(\"appengine\", \"v1\", cache_discovery=False)\n apps = appengine.apps()\n\n # Get the target app's serving status\n target_app = apps.get(appsId=APP_NAME).execute()\n current_status = target_app[\"servingStatus\"]\n\n # Disable target app, if necessary\n if current_status == \"SERVING\":\n print(f\"Attempting to disable app {APP_NAME}...\")\n body = {\"servingStatus\": \"USER_DISABLED\"}\n apps.patch(appsId=APP_NAME, updateMask=\"serving_status\", body=body).execute()\n\n 2. Add the following dependencies to your function's `requirements.txt` file:\n\n google-api-python-client==2.131.0\n\n 3. Under **Function to execute** enter `limit_use_appengine`.\n\n 4. Click **Environment variables, networking, timeouts and more**.\n\n 5. Select a service account that has the **App Engine Admin** role.\n The [App Engine default service\n account](/appengine/docs/standard/default-service-account) has this role\n by default.\n\n3. [Test the function](/billing/docs/how-to/notify#test_your_cloud_function).\n\nWhen the budget alert is triggered, an email is sent to [users in your\nCloud Billing account](/billing/docs/how-to/budgets), and\nyour function starts disabling your app. It may take few minutes to complete\nthis process.\n\nTo verify that the function ran successfully, view the App Engine\ndashboard. A message appears near the top to indicate that your app is disabled.\n\n[Go to the App Engine dashboard](https://console.cloud.google.com/appengine)\n\nWhen you want your app to continue serving requests, go to\n**Application settings** and click **Enable application**.\n\n[Go to Application settings](https://console.cloud.google.com/appengine/settings)"]]