全部產品
Search
文件中心

:CreateDataSource - 建立資料來源

更新時間:Mar 21, 2026

該介面用於建立DataWorks資料來源。

調試

您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。

調試

授權資訊

當前API暫無授權資訊透出。

請求參數

名稱

類型

必填

描述

樣本值

ProjectId

integer

資料來源所在的 DataWorks 工作空間 ID。您可以通過 ListProjects 介面擷取工作空間 ID。

1

Name

string

資料來源的名稱。

abc

Description

string

資料來源的描述資訊。

abc

DataSourceType

string

資料來源的類型。常用類型如下:

  • odps

  • mysql

  • rds

  • oss

  • sqlserver

  • polardb

  • oracle

  • mongodb

  • emr

  • postgresql

  • analyticdb_for_mysql

  • hybriddb_for_postgresql

  • holo

rds

SubType

string

資料來源的子類型。使用如下:

  • 當 DataSourceType 參數配置為 RDS 時,SubType 參數生效。

  • 如果 DataSourceType 參數配置為 RDS,SubType 參數支援配置為 mysql、sqlserver 或 postgresql。

mysql

EnvType

integer

資料來源所屬的環境,包括 0(開發環境)和 1(生產環境)。

1

Content

string

資料來源的詳細資料。部分常用資料來源範例如下:

  • odps

    {
      "accessId": "*****",
      "accessKey": "*****",
      "authType": 2,
      "endpoint": "http://service.odps.aliyun.com/api",
      "project": "xsaxsax",
      "tag": "public"
    }
    

  • mysql

    {
      "database": "xsaxsa",
      "instanceName": "rm-xsaxsa",
      "password": "xsaxsa",
      "rdsOwnerId": "xasxsa",
      "regionId": "cn-shanghai",
      "tag": "rds",
      "username": "xsaxsa"
    }
    

  • rds

    {
      "configType": 1,
      "tag": "rds",
      "database": "xsaxsa",
      "username": "xsaxsa",
      "password": "xssaxsa$32050",
      "instanceName": "rm-xsaxs",
      "rdsOwnerId": "11111111"
    }
    

  • oss

    {
      "accessId": "*****",
      "accessKey": "*****",
      "bucket": "xsa-xs-xs",
      "endpoint": "http://oss-cn-shanghai.aliyuncs.com",
      "tag": "public"
    }
    

  • sqlserver

    {
      "jdbcUrl": "jdbc:sqlserver://xsaxsa-xsaxsa.database.xxx.cn:123;DatabaseName=xsxs-xsxs",
      "password": "sdasda$fs",
      "tag": "public",
      "username": "sxaxacdacdd"
    }
    

  • polardb

    {
      "clusterId": "pc-sdadsadsa",
      "database": "dsadsadsa",
      "ownerId": "121212122",
      "password": "sdasdafssa",
      "region": "cn-shanghai",
      "tag": "polardb",
      "username": "asdadsads"
    }
    

  • redis

    {    
    "password": "xxxxxx",   
     "address":"[{\"host\":\"xxxxxxx.redis.rds.aliyuncs.com\",\"port\":6379}]",    
    "tag": "public"
    }
    

  • oracle

    {
      "jdbcUrl": "jdbc:oracle:saaa:@xxxxx:1521:PROD",
      "password": "sxasaxsa",
      "tag": "public",
      "username": "sasfadfa"
    }
    

  • mongodb

    {
      "address": "[\"xsaxxsa.mongodb.rds.aliyuncs.com:3717\"]",
      "database": "admin",
      "password": "sadsda@",
      "tag": "public",
      "username": "dsadsadas"
    }
    

  • emr

    {
      "accessId": "*****",
      "emrClusterId": "C-dsads",
      "emrResourceQueueName": "default",
      "emrEndpoint": "emr.aliyuncs.com",
      "accessKey": "*****",
      "emrUserId": "224833315798889783",
      "name": "sasdsadsa",
      "emrAccessMode": "simple",
      "region": "cn-shanghai",
      "authType": "2",
      "emrProjectId": "FP-sdadsad"
    }
    

  • postgresql

    {
      "jdbcUrl": "jdbc:postgresql://xxxx:1921/ssss",
      "password": "sdadsads",
      "tag": "public",
      "username": "sdsasda"
    }
    

  • analyticdb_for_mysql

    {
      "instanceId": "am-sadsada",
      "database": "xsxsx",
      "username": "xsxsa",
      "password": "asdadsa",
      "connectionString": "am-xssxsxs.ads.aliyuncs.com:3306"
    }
    

  • hybriddb_for_postgresql

    {
      "connectionString": "gp-xsaxsaxa-master.gpdbmaster.rds.aliyuncs.com",
      "database": "xsaxsaxas",
      "password": "xsaxsaxsa@11",
      "instanceId": "gp-xsaxsaxsa",
      "port": "541132",
      "ownerId": "xsaxsaxsas",
      "username": "sadsad"
    }
    

  • holo

    {
      "accessId": "*****",
      "accessKey": "*****",
      "database": "xsaxsaxsa",
      "instanceId": "xsaxa",
      "tag": "aliyun"
    }
    

  • kafka

    {
      "instanceId": "xsax-cn-xsaxsa",
      "regionId": "cn-shanghai",
      "tag": "aliyun",
      "ownerId": "1212121212112"
    }
    

{"database":"dbname","instanceName":"instancename","password":"password","rdsOwnerId":"123","username":"username"}

返回參數

名稱

類型

描述

樣本值

object

返回結果。

HttpStatusCode

string

請求返回碼。

200

Data

integer

資料來源 ID。

123

RequestId

string

請求 ID。

0bc141151593763****

Success

boolean

請求是否成功。

true

樣本

正常返回樣本

JSON格式

{
  "HttpStatusCode": "200",
  "Data": 123,
  "RequestId": "0bc141151593763****",
  "Success": true
}

錯誤碼

HTTP status code

錯誤碼

錯誤資訊

描述

400 Invalid.Tenant.ConnectionNotExists The connection does not exist. 資料來源不存在。
400 Invalid.Tenant.ProjectNotExists The project does not exist. 專案不存在。
400 Invalid.Tenant.UserNotInProject The user is not in the project. 使用者不在專案中。
400 ConnectionAlreadyExist The connection with envType %s and name %s already exists. 串連串名稱重複
400 DataSource.CheckRamRoleFailure Failed to check the RAM role. AccountId %s. roleArn %s. 校正資料來源許可權失敗
400 DataSource.ConnectionStrProperty.PatternNotMatch The pattern value %s is invalid. The correct pattern is %s. 資料來源串連串屬性不匹配規則
400 Invalid.DataSource.DataSourceTypeNotSupport The dataSourceType %s and subType %s are not supported. 資料來源類型暫不支援
400 Invalid.Param.Odps.EngineIdOrConnectStrEmpty Either the compute engine ID or the connection string must be specified when data source type is ODPS.
400 MissingParam.ConnectionStr.Property You must specify property %s required by the data source connection string. 資料來源串連串資訊必填屬性缺失
400 Invalid.DataSource.DataSourceTypeNotExist The data source type %s does not exist. 資料來源類型不存在。
403 Invalid.Tenant.UserIsNotProjectOwnerOrAdmin The user is not a project administrator or owner. 使用者不是專案負責人或者專案系統管理員。
403 Invalid.Tenant.UserNotInTenant The user is not in tenant. 使用者不在租戶中。

訪問錯誤中心查看更多錯誤碼。

變更歷史

更多資訊,參考變更詳情