[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-20。"],[[["\u003cp\u003eApp Engine services are defined by \u003ccode\u003eapp.yaml\u003c/code\u003e files, which specify scaling type, runtime, handlers, and other resource settings for a service version, with multiple versions supported via multiple YAML files.\u003c/p\u003e\n"],["\u003cp\u003eApps can be structured with separate directories or repositories for each service, each containing its \u003ccode\u003eapp.yaml\u003c/code\u003e file and associated code.\u003c/p\u003e\n"],["\u003cp\u003eOptional configuration files like \u003ccode\u003edispatch.yaml\u003c/code\u003e, \u003ccode\u003eindex.yaml\u003c/code\u003e, and \u003ccode\u003ecron.yaml\u003c/code\u003e reside in the root of the \u003ccode\u003edefault\u003c/code\u003e service and control app-wide settings.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine instances can experience unexpected failures, so applications should be stateless, use queues for asynchronous tasks, and be designed to handle restarts and load balancing.\u003c/p\u003e\n"],["\u003cp\u003eFile names used in App Engine must be UTF-8 compatible, but there are no restrictions on the character encoding used within files.\u003c/p\u003e\n"]]],[],null,["# Structuring web services in App Engine\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\n### Region ID\n\nThe \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e is an abbreviated code that Google assigns\nbased on the region you select when you create your app. The code does not\ncorrespond to a country or province, even though some region IDs may appear\nsimilar to commonly used country and province codes. For apps created after\nFebruary 2020, \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e`.r` is included in\nApp Engine URLs. For existing apps created before this date, the\nregion ID is optional in the URL.\n\nLearn more\n[about region IDs](/appengine/docs/standard/python/how-requests-are-routed#region-id). \nOK\n\nThis guide covers how to structure the services and related resources of your\nApp Engine app.\n\nDirectory structure\n-------------------\n\nEach version of your App Engine service is defined in an\n[`app.yaml`](/appengine/docs/standard/reference/app-yaml)\nconfiguration file. For simple apps, the minimum requirement for deployment is\nto define the `app.yaml` file. The `app.yaml` file acts as a deployment\ndescriptor and defines the scaling type and the\nruntime, handlers, and other resource\nsettings for a specific\nversion of a service. If you are deploying several versions of a service, you\ncan create multiple YAML files in the same directory to represent the\nconfiguration for each of your versions.\n| **Note:** For the Java runtime, the file organization depends on which Java runtime you are using. You might need a WAR file or a JAR file, one for each service in your app. See the appropriate Java runtime developer guide for details.\n\nFor each service, you can create separate directories in the root of your app\nwhen you are developing locally. If you host your app out of a version control\nsystem (VCS), for example GitHub, you can also structure your app to use\nseparate directories in a repository, or use separate repositories for each\nservice. Each directory or repository should represent a single service and\ncontain that service's `app.yaml` file along with the associated source code.\n\nYou have the option of specifying a unique name for each of your service's\n`app.yaml` file. For example, you can name a configuration file after your\nservice, or use unique names to represent each version of that particular\nservice, like `service1.yaml` or `app.standard.yaml`.\n\nThe other [optional configuration files](#optional_configuration_files) should\nreside in the root directory or repository of the\n[`default` service](#the_default_service) of your app. These optional\nconfiguration files apply app-wide settings that are not specific to a\nparticular service, including the `dispatch.yaml`, `index.yaml`, and `cron.yaml`\nfiles.\n\n### Examples\n\nA simple app only requires the `app.yaml` to be added in the same location as\nthe app's source files. For a single service app, that app will only include the\n[`default` service](#the_default_service) and all the files can live in the same\ndirectory, at the root of that app:\n\nThe following example demonstrates how to structure what an app with three services might look\nlike if you are developing your app locally. The optional `dispatch.yaml` file has\nbeen added to that app in the root directory. Also in the root are three\ndirectories for each of the app's services. The subdirectory for `service1`\nincludes the source and configuration files for that service. Similarly, both\n`service2` and `service3` are in separate directories, which contain each\nservice's files, although `service3` includes two versions of the YAML\nconfiguration file:\n\nIn the following example, a single service has the optional `dispatch.yaml` file\nand two configuration files that represent different versions of that service,\n`service1.yaml` and `service2.yaml`:\n\nDesign considerations for instance uptime\n-----------------------------------------\n\nHardware or software failures that cause early termination or frequent instance\nrestarts can occur without warning and can take considerable time to resolve.\nYour application should be able to handle such failures.\n\nHere are some good strategies for avoiding downtime due to instance restarts:\n\n- Reduce the amount of time it takes for your instances restart or for new ones to start.\n- For long-running computations, periodically create checkpoints so that you can resume from that state.\n- Your app should be \"stateless\" so that nothing is stored on the instance.\n- Use queues for performing asynchronous task execution.\n- If you configure your instances to manual scaling:\n - Use load balancing across multiple instances.\n - Configure more instances than required to handle normal traffic.\n - Write fall-back logic that uses cached results when a manual scaling instance is unavailable.\n\nLearn more about instances at [How instances are\nmanaged](/appengine/docs/standard/how-instances-are-managed).\n\nThe `default` service\n---------------------\n\nEvery App Engine application includes a `default` service. You must\ndeploy the initial version of your app to the `default` service before you can\ncreate and deploy additional services to your app.\n\nThe default service can be optionally specified in the `app.yaml` with the setting\n`service: default`.\n\nIf you use Java and the legacy bundled services, you can\nspecify the default service in the `appengine-web.xml` with the\nsetting `\u003cservice\u003edefault\u003c/service\u003e`.\n\nRequests sent to your app using your Google Cloud project are sent to the\n`default` service, for example,\n`https://`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.`\u003cvar translate=\"no\"\u003e\u003ca href=\"#appengine-urls\" style=\"border-bottom: 1px dotted #999\" class=\"devsite-dialog-button\" data-modal-dialog-id=\"regional_url\" track-type=\"progressiveHelp\" track-name=\"modalHelp\" track-metadata-goal=\"regionalURL\"\u003eREGION_ID\u003c/a\u003e\u003c/var\u003e`.r.appspot.com`. To learn\nmore about targeting your other services, see [Communicating Between\nServices](/appengine/docs/standard/communicating-between-services).\n\nOptional configuration files\n----------------------------\n\nThe following configuration files control optional features that apply to all of\nthe services in an individual app. See the following topics for details about\neach of the optional features:\n\n- [`cron.yaml`](/appengine/docs/standard/scheduling-jobs-with-cron-yaml) configures regularly scheduled tasks that operate at defined times or regular intervals.\n- [`dispatch.yaml`](/appengine/docs/standard/reference/dispatch-yaml) overrides routing default rules by sending incoming requests to a specific service based on the path or hostname in the URL.\n- [`index.yaml`](/appengine/docs/standard/configuring-datastore-indexes-with-index-yaml) specifies which indexes your app needs if using Datastore queries.\n\nFile names\n----------\n\nApp Engine runs apps in a container on an up-to-date Ubuntu Linux\ndistribution. The file names you use in the App Engine standard environment must be\nUTF-8 compatible, either UTF-8 or something that can be safely auto-converted\nto UTF-8. If your file names use different encodings, deploy your app from a machine\nwith UTF-8 compatible filename language settings.\n\nDeployment fails if file names are not UTF-8 compatible. Note that\nthere's no restriction on the character\nencoding you use within a file.\n\nData and file storage considerations\n------------------------------------\n\nFrom App Engine, you can easily access other Google Cloud\nservices such as [Datastore](/datastore), [Cloud SQL](/sql), and\n[Cloud Storage](/storage).\n\nYou also have the option to use an external or third-party database if that\ndatabase is supported by your language and accessible from your\nApp Engine instance.\n\nFor details about storing files in Google Cloud or externally, see\n[Understanding Data and File Storage](/appengine/docs/standard/storage-options).\n\nYou can also choose how you want to serve your static content. You can serve\nyour app's static content directly from that app in App Engine, host\nyour static content on a Google Cloud option like\nCloud Storage, or use a third-party content delivery network (CDN).\nFor more information about serving static content, see [Serving Static\nFiles](/appengine/docs/standard/serving-static-files).\n\nWhat's next\n-----------\n\nIf you are working with multiple services and want to deploy them together, see the steps to [deploy multiple services](https://cloud.google.com/appengine/docs/standard/nodejs/testing-and-deploying-your-app#deploying_multiple_services)."]]