This page shows how to get started with the Cloud Client Libraries for the Dataproc API. However, we recommend using the older Google APIs Client Libraries if running on Google App Engine standard environment. Read more about the client libraries for Cloud APIs in Client Libraries Explained.
Dataproc Cloud Client Libraries may be in alpha or beta stage. See the library reference for details.Installing the client library
C#
For more information, see Setting Up a C# Development Environment.
Also see Google.Cloud.Dataproc.V1 InstallationGo
For more information, see Setting Up a Go Development Environment.
go get -u cloud.google.com/go/dataproc/apiv1
For more information, see Install the Cloud Client Libraries for Go.
Java
For more information, see Setting Up a Java Development Environment.
If you are using Maven, add this to your pom.xml file:<dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-dataproc</artifactId> <version>insert dataproc-library-version here</version> </dependency>
If you are using Gradle, add this to your dependencies:
compile group: 'com.google.cloud', name: 'google-cloud-dataproc', version: 'insert dataproc-library-version here'
Node.js
For more information, see Setting Up a Node.js Development Environment.
npm install --save @google-cloud/dataproc
PHP
For more information, see Using PHP on Google Cloud.
composer require google/cloud
Python
For more information, see Setting Up a Python Development Environment.
pip install --upgrade google-cloud-dataproc
Ruby
For more information, see Setting Up a Ruby Development Environment.
gem install google-cloud-dataproc
Setting up authentication
To run the client library, you must first set up authentication by creating a service account and setting an environment variable. Complete the following steps to set up authentication. For other ways to authenticate, see the GCP authentication documentation.
Cloud Console
创建服务帐号:
-
在 Cloud Console 中,转到创建服务帐号页面。
转到“创建服务帐号” - 选择一个项目。
-
在服务帐号名称字段中,输入一个名称。 Cloud Console 会根据此名称填充服务帐号 ID 字段。
在服务帐号说明字段中,输入说明。例如,
Service account for quickstart
。 - 点击创建。
-
点击选择角色字段。
在快速访问下,点击基本,然后点击所有者。
- 点击继续。
-
点击完成以完成服务帐号的创建过程。
不要关闭浏览器窗口。您将在下一步骤中用到它。
创建服务帐号密钥:
- 在 Cloud Console 中,点击您创建的服务帐号的电子邮件地址。
- 点击密钥。
- 依次点击添加密钥和创建新密钥。
- 点击创建。JSON 密钥文件将下载到您的计算机上。
- 点击关闭。
命令行
您可以使用本地机器上的 Cloud SDK 或在 Cloud Shell 中运行以下命令。
-
创建服务帐号。将 NAME 替换为服务帐号的名称。
gcloud iam service-accounts create NAME
-
向服务帐号授予权限。将 PROJECT_ID 替换为您的项目 ID。
gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:NAME@PROJECT_ID.iam.gserviceaccount.com" --role="roles/owner"
-
生成密钥文件。将 FILE_NAME 替换为密钥文件的名称。
gcloud iam service-accounts keys create FILE_NAME.json --iam-account=NAME@PROJECT_ID.iam.gserviceaccount.com
通过设置环境变量 GOOGLE_APPLICATION_CREDENTIALS
向应用代码提供身份验证凭据。
将 [PATH] 替换为包含您的服务帐号密钥的 JSON 文件的路径。此变量仅适用于当前的 Shell 会话,因此,如果您打开新的会话,请重新设置该变量。
Linux 或 macOS
export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
例如:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"
Windows
使用 PowerShell:
$env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
例如:
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\my-key.json"
使用命令提示符:
set GOOGLE_APPLICATION_CREDENTIALS=[PATH]
Using the client library
The following example shows how to use the client library.
Go
Before trying this sample, follow the Go setup instructions in the Dataproc Quickstart Using Client Libraries. For more information, see the Dataproc Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Dataproc Quickstart Using Client Libraries. For more information, see the Dataproc Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Dataproc Quickstart Using Client Libraries. For more information, see the Dataproc Node.js API reference documentation.
.Python
Before trying this sample, follow the Python setup instructions in the Dataproc Quickstart Using Client Libraries. For more information, see the Dataproc Python API reference documentation.