[英]Starting Google app engine instances programmatically
目前,我正在刪除應用引擎活動實例,如下所述:刪除實例
代碼:
import requests
from apiclient.discovery import build
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file('credentials.json')
scoped_credentials = credentials.with_scopes(['https://www.googleapis.com/auth/appengine.admin',"https://www.googleapis.com/auth/cloud-platform"])
appengine = build(serviceName="appengine",version="v1",credentials=scoped_credentials)
VERSION_ID = "version_id"
PROJECT_ID = "project_id"
SERVICE_ID = "appengine_service_name"
APP_URL = "http://some_url.com"
active_instances_dict = appengine.apps().services().versions().instances().list(servicesId=SERVICE_ID,appsId=PROJECT_ID,versionsId=VERSION_ID).execute()
list_of_instances = active_instances_dict["instances"]
for instance in list_of_instances:
appengine.apps().services().versions().instances().delete(servicesId=SERVICE_ID,appsId=PROJECT_ID,
versionsId=VERSION_ID,instancesId=instance["id"]).execute()
此后,僅當有人訪問 Web 應用程序時才會初始化新實例。
有沒有辦法以編程方式初始化實例以確保已經有一個訪問 Web 應用程序的人的活動實例?
注意:我使用的是具有自動縮放功能的標准 pyhton 3.7 運行時
無需以編程方式執行此操作 - 如果您使用automatic_scaling
,則只需在app.yaml文件中指定min_instances 即可。
將min_instances
設置為1
將確保您的應用程序有一個活動實例准備好為流量提供服務。 請注意,這也需要您啟用預熱請求。
請記住,但是,你將被收取指定其是否正在接收流量或沒有實例的數量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.