无法使用GCP云功能(Python)触发数据流模板

时间:2019-08-09 09:26:26

标签: python function flask google-cloud-dataflow serverless

我已经使用python flask编写了云函数代码来触发我的数据流模板,但是当我访问由云函数提供的网址时,会出现错误“错误:无法处理请求”。

import flask
import datetime
from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials


app = flask.Flask(__name__)


def main(request):
    with app.app_context():
        credentials = GoogleCredentials.get_application_default()
        service = build('dataflow', 'v1b3', credentials=credentials)
        JOBNAME = 'readwritetesting-{}'.format(datetime.datetime.now().strftime('%Y-%m-%d-%H%M%S'))
        PROJECT = os.environ.get('project_id')
        BUCKET = os.environ.get('BUCKET')
        TEMPLATE = 'bqtest'
        GCSPATH = "gs://{bucket}/templates/{template}".format(bucket=BUCKET, template=TEMPLATE)

        BODY = {"jobName": "{jobname}".format(jobname=JOBNAME),
                "parameters": {

                },
                "environment": {
                    "tempLocation": "gs://{bucket}/temp".format(bucket=BUCKET),
                    "zone": "europe-west1-b"
                }
                }
        request = service.projects().templates().launch(projectId=PROJECT, gcsPath=GCSPATH, body=BODY)
        response = request.execute()
        return 'Triggered'

0 个答案:

没有答案