为什么没有任何 SDK 可以调用 Cloud SQL API?

Why aren't there any SDKs to call Cloud SQL API?

我想调用 Cloud SQL API,如下所述,来自 Cloud Functions。

而且我找到了调用 GCP APIs 的库。

但是,似乎没有任何云模块 SQL。

我想知道为什么它没有实现。 API 相对较新的原因是什么?或者我误解了库的目的,实际上它不应该在库中实现?

您可以使用gcloud sdk 调用api。如果您只是想导出数据库,请查看此文档:https://cloud.google.com/sdk/gcloud/reference/sql/instances/export

在您 linked 页面的底部,您将找到不同语言的示例代码,以通过构建客户端来调用 API。例如 Node.js 的示例代码如下所示:

const {google} = require('googleapis');
var sqlAdmin = google.sqladmin('v1beta4');

authorize(function(authClient) {
  var request = {
    // Project ID of the project that contains the instance to be exported.
    project: 'my-project',  // TODO: Update placeholder value.

    // Cloud SQL instance ID. This does not include the project ID.
    instance: 'my-instance',  // TODO: Update placeholder value.

    resource: {
      // TODO: Add desired properties to the request body.
    },

    auth: authClient,
  };

  sqlAdmin.instances.export(request, function(err, response) {
    if (err) {
      console.error(err);
      return;
    }

    // TODO: Change code below to process the `response` object:
    console.log(JSON.stringify(response, null, 2));
  });
});

function authorize(callback) {
  google.auth.getApplicationDefault(function(err, authClient) {
    if (err) {
      console.error('authentication failed: ', err);
      return;
    }
    if (authClient.createScopedRequired && authClient.createScopedRequired()) {
      var scopes = ['https://www.googleapis.com/auth/cloud-platform'];
      authClient = authClient.createScoped(scopes);
    }
    callback(authClient);
  });
}

要从 Cloud Function 连接到云 SQL 实例,请遵循文档 here