OAuth: Starting a Google Compute Instance from within Google App Engine

前端 未结 2 753
礼貌的吻别
礼貌的吻别 2021-02-09 01:06

I have a Google App Engine web app that runs the majority of my site. However, for certain functions, I need a linux machine. I would like my Google App Engine app to automatica

2条回答
  •  悲哀的现实
    2021-02-09 01:21

    Here is a complete example of using service accounts and App Engine cron tasks to stop instances after they've been running for a while: (opposite of starting instances, but the authorization code will be the same)

    https://github.com/GoogleCloudPlatform/compute-appengine-timeout-python

    AppAssertionCredentials handles the access token using this code:

    # Obtain App Engine AppAssertion credentials and authorize HTTP connection.
    # https://developers.google.com/appengine/docs/python/appidentity/overview
    credentials = AppAssertionCredentials(
        scope='https://www.googleapis.com/auth/compute')
    HTTP = credentials.authorize(httplib2.Http(memcache))
    
    # Build object for the 'v1beta15' version of the GCE API.
    # https://developers.google.com/compute/docs/reference/v1beta13/
    compute = build('compute', 'v1beta15', http=HTTP)
    

提交回复
热议问题