Presently, I am deleting app engine active instances as outlined here: deleting instances
Code:
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()
After this, new instances are initialized only when someone accesses the web app.
Is there a way I can programmatically initialize the instances to ensure there is already an active instance for someone accessing the web app?
Note: I'm using Standard Python 3.7 runtime with auto scaling