Modules API verwenden
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Die Modules API bietet Funktionen, die Informationen zur aktuellen Betriebsumgebung (Modul, Version und Instanz) zurückgeben.
Außerdem verfügt die Modules API über Funktionen zum Abrufen der Adresse eines Moduls, einer Version oder einer Instanz. Auf diese Weise kann eine Anwendung sowohl in Entwicklungs- als auch in Produktionsumgebungen Anfragen von einer Instanz an eine andere senden.
Sie müssen das Modul google.appengine.api.modules
aus dem SDK importieren.
Das folgende Codebeispiel zeigt, wie Sie den Modulnamen und die Instanz-ID für eine Anfrage abrufen können:
Die Instanz-ID eines automatisch skalierten Moduls wird als eindeutiger base64-codierter Wert zurückgegeben, z. B. e4b565394caa
.
Sie können zwischen Modulen in derselben Anwendung kommunizieren. Rufen Sie dazu den Hostnamen des Zielmoduls ab:
Sie können auch den URL-Abrufdienst verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-09-04 (UTC).
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (UTC)."],[[["\u003cp\u003eThis API supports first-generation runtimes and can be used when upgrading to corresponding second-generation runtimes.\u003c/p\u003e\n"],["\u003cp\u003eThe Modules API provides functions to access information about the current operating environment, including module, version, and instance details.\u003c/p\u003e\n"],["\u003cp\u003eThe API allows retrieving the address of a specific module, version, or instance, facilitating inter-instance communication within an application.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize the Modules API, you must import the \u003ccode\u003egoogle.appengine.api.modules\u003c/code\u003e module from the SDK.\u003c/p\u003e\n"],["\u003cp\u003eThe API can retrieve the hostname of a specific target module to allow communication between modules in the same app.\u003c/p\u003e\n"]]],[],null,["# Using the Modules API\n\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| python3\n|\n| /services/access). If you are updating to the App Engine Python 3 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/python-differences) to learn about your migration options for legacy bundled services.\n\nThe Modules API provides functions that return information about the current\noperating environment (module, version, and instance).\n\nThe Modules API also has functions that retrieve the address of a module, a\nversion, or an instance. This allows an application to send requests from one\ninstance to another, in both the development and production environments.\n\nYou must import the `google.appengine.api.modules` module from the SDK. \n\n from google.appengine.api import modules\n\nThe following code sample shows how to get the module name and instance id for\na request: \n\n module = modules.get_current_module_name()\n instance_id = modules.get_current_instance_id()\n self.response.write(\n 'module_id={}&instance_id={}'.format(module, instance_id))\n\nThe instance ID of an automatic scaled module will be returned as a unique\nbase64 encoded value, e.g. `e4b565394caa`.\n\nYou can communicate between modules in the same app by fetching the hostname of\nthe target module: \n\n backend_hostname = modules.get_hostname(module='my-backend')\n url = \"http://{}/\".format(backend_hostname)\n try:\n result = urllib2.urlopen(url).read()\n self.response.write('Got response {}'.format(result))\n except urllib2.URLError:\n pass\n\nYou can also use the [URL Fetch](/appengine/docs/legacy/standard/python/issue-requests) service."]]