Error while executing Dataflow template using cloud function

前端 未结 1 1691
时光取名叫无心
时光取名叫无心 2021-01-21 22:04

Getting below error while trying to execute custom dataflow template using Google Cloud function.

Error:\"problem running dataflow template, error was: { Error: A Forbid

相关标签:
1条回答
  • 2021-01-21 22:55

    The google-cloud node library does not yet support the Dataflow API, so the current way to use that API is the googleapis library.

    Following the instructions there, I've tried to launch a Dataflow job with a Google-provided template using an HTTP-triggered function, and had no issues:

    const {google} = require('googleapis');
    const project = "your-project-id"
    
    exports.launchDataflowTemplate = (req, res) => {
        let result;
        google.auth.getApplicationDefault(function(err, authClient, projectId) {
                if (err) {
                    throw err;
                }
                if (authClient.createScopedRequired && authClient.createScopedRequired()) {
                    authClient = authClient.createScoped([
                        'https://www.googleapis.com/auth/cloud-platform',
                        'https://www.googleapis.com/auth/compute',
                        'https://www.googleapis.com/auth/compute.readonly',
                        'https://www.googleapis.com/auth/userinfo.email'
                    ]);
                }
                var dataflow = google.dataflow({
                    version: "v1b3",
                    auth: authClient
                });
    
                var launchParams = {
                    "inputFilePattern": "gs://your-input-bucket/*.gz",
                    "outputDirectory": "gs://your-result-bucket/",
                    "outputFailureFile": "gs://your-logs-bucket/error.csv"
                };
    
                var env = {
                   "tempLocation": "gs://your-staging-bucket/temp",
                   "zone": "us-central1-f"
                }
    
    
                var opts = {
                    projectId: project,
                    gcsPath: "gs://dataflow-templates/latest/Bulk_Decompress_GCS_Files",
                    resource: {
                        parameters: launchParams,
                        environment: env
                    }
                };
    
                dataflow.projects.templates.launch(opts, (err, result) => {
                    if (err) {
                        throw err;
                    }
                    res.send(result.data);
                });
        });
    };
    
    0 讨论(0)
提交回复
热议问题