Menguji dan men-deploy aplikasi yang telah diupgrade di Python 3
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
ID region
REGION_ID adalah kode singkat yang ditetapkan Google berdasarkan region yang Anda pilih saat membuat aplikasi. Kode ini tidak sesuai dengan negara atau provinsi, meskipun beberapa ID region mungkin tampak mirip dengan kode negara dan provinsi yang umum digunakan. Untuk aplikasi yang dibuat setelah Februari 2020, REGION_ID.r disertakan dalam URL App Engine. Untuk aplikasi lama yang dibuat sebelum tanggal tersebut, ID region bersifat opsional dalam URL.
Anda mungkin perlu menghabiskan banyak waktu untuk memperbaiki masalah kompatibilitas yang tidak
terlihat sampai Anda menjalankan aplikasi yang telah diupgrade di lingkungan Python 3.
Untuk menghindari penggunaan data produksi dan kuota Google Cloud selama pengujian, Anda dapat menggunakan emulator berikut:
Layanan Google Cloud lainnya seperti Cloud Storage dan
Memorystore tidak menyediakan emulator.
Menguji secara lokal
Untuk menguji fungsionalitas aplikasi sebelum di-deploy, ikuti petunjuk untuk menjalankan secara lokal di runtime Python 3.
Menguji di App Engine sebelum mengalihkan traffic
Sebelum mengarahkan traffic ke aplikasi Python yang telah diupgrade, deploy aplikasi ke runtime App Engine Python 3 untuk pengujian selanjutnya. Misalnya,
untuk menguji layanan default aplikasi Anda:
Sekarang Anda dapat menguji versi baru di lingkungan runtime App Engine. Anda dapat men-debug aplikasi dengan melihat log-nya. Untuk informasi
selengkapnya, lihat Menulis Log Aplikasi.
Permintaan yang dikirim ke https://PROJECT_ID.REGION_ID.r.appspot.com dirutekan ke versi yang sebelumnya dikonfigurasi untuk menerima traffic.
Untuk menguji versi baru layanan lain, ikuti proses yang sama, tetapi ganti default di URL dengan nama layanan Anda:
Untuk informasi selengkapnya tentang menargetkan layanan dan versi tertentu, lihat Cara Permintaan Dirutekan.
Memigrasikan traffic ke aplikasi Anda
Jika Anda sudah siap mengirim traffic ke versi baru:
Perbarui variabel lingkungan di file app.yaml untuk mengirim permintaan ke database produksi dan layanan lainnya, bukan emulator atau data pengujian yang Anda gunakan.
Cegah traffic agar tidak dirutekan secara otomatis ke versi baru saat deployment:
gcloudappdeploy--no-promote
Setelah mengonfirmasi bahwa aplikasi Anda berinteraksi dengan database produksi dan datastore, gunakan konsol Google Cloud untuk memigrasikan traffic:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-19 UTC."],[],[],null,["# Testing and deploying your upgraded app in Python 3\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/python3/how-requests-are-routed#region-id). \nOK\n\nAfter you upgrade your app to be compatible with both Python 2 and Python 3:\n\n1. [Test the app in a local Python 3 environment](#test_locally).\n\n2. [Deploy and test in App Engine](#testing-on-app-engine) without\n shifting traffic to your app.\n\n3. [Migrate traffic to your app](#shifting_traffic).\n\nYou may need to spend significant time fixing compatibility issues that aren't\nvisible until you run your upgraded app in a Python 3 environment.\n\nTo avoid using production data and Google Cloud quota during testing, you can\nuse the following emulators:\n\n- [Datastore](/datastore/docs/tools/datastore-emulator)\n- [Bigtable](/bigtable/docs/emulator)\n- [Pub/Sub](/pubsub/docs/emulator)\n\nOther Google Cloud services such as Cloud Storage and\nMemorystore don't provide emulators.\n\nTesting locally\n---------------\n\nTo test your app's functionality before deploying, follow the instructions for\n[running locally](/appengine/docs/standard/testing-and-deploying-your-app#running_locally)\nin the Python 3 runtime.\n\nTesting on App Engine before shifting traffic\n---------------------------------------------\n\nBefore routing traffic to your upgraded Python app, deploy the app to the\nApp Engine Python 3 runtime for another round of testing. For example,\nto test your app's `default` service:\n\n1. Make sure you've\n [updated the app's configuration files](/appengine/docs/standard/python3/migrate-to-python3/config-files) for\n compatibility with the Python 3 runtime.\n\n Don't change environment variables that send requests to emulators or\n test databases until you're ready to [shift traffic to your app](#shifting_traffic).\n2. Deploy your new version, but prevent traffic from automatically routing\n to the new version:\n\n ```bash\n gcloud app deploy --no-promote\n ```\n\n \u003cbr /\u003e\n\n3. Access your new version by navigating to the following URL:\n\n\n `https://`\u003cvar translate=\"no\"\u003eVERSION_ID\u003c/var\u003e`-dot-default-dot-`\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`\n | **Note:** You can find the version ID in the [Google Cloud console](https://console.cloud.google.com/appengine/versions), or specify one when you deploy with the `--version flag`. The gcloud CLI also outputs the version ID when you deploy.\n\nNow you can test your new version in the App Engine runtime\nenvironment. You can debug your application by viewing its logs. For more\ninformation, see [Writing Application Logs](/appengine/docs/standard/writing-application-logs).\n\nRequests sent to\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`\nare routed to the version previously configured to receive traffic.\n\nTo test new versions of other services, follow the same process, but replace\n`default` in the URL with your service's name:\n\n\n`https://`\u003cvar translate=\"no\"\u003eVERSION\u003c/var\u003e`-dot-`\u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e`-dot-`\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`\n\nFor more information about targeting specific services and versions, see\n[How Requests are Routed](/appengine/docs/standard/how-requests-are-routed).\n\nMigrating traffic to your app\n-----------------------------\n\nWhen you're ready to send traffic to the new version:\n\n1. Update environment variables in your `app.yaml` file to send requests to your\n production databases and other services instead of any emulators or test\n data you were using.\n\n2. Prevent traffic being automatically routed to your new version upon deployment:\n\n \u003cbr /\u003e\n\n ```bash\n gcloud app deploy --no-promote\n ```\n\n \u003cbr /\u003e\n\n3. When you've confirmed that your app is interacting with your production databases\n and datastores, use the Google Cloud console to migrate traffic:\n\n [Manage versions](https://console.cloud.google.com/appengine/versions)\n\n Select the latest version of your upgraded app and click\n **Migrate traffic**."]]