调用CreateDataSource接口,创建Dataworks数据源。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

请求参数

名称 类型 是否必选 示例值 描述
Action String CreateDataSource

要执行的操作。

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

数据源的详细信息。部分常用数据源样例如下:

  • odps

{
  "accessId": "xssssss",
  "accessKey": "xsaxsaxsa",
  "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": "sssssxx",
  "accessKey": "xsaxaxsaxs",
  "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"
}
  • 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": "xsaxsa",
  "emrClusterId": "C-dsads",
  "emrResourceQueueName": "default",
  "emrEndpoint": "emr.aliyuncs.com",
  "accessKey": "dsadsad",
  "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": "xsaxsaxs",
  "accessKey": "xsaxsaxsa",
  "database": "xsaxsaxsa",
  "instanceId": "xsaxa",
  "tag": "aliyun"
}
  • kafka

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

数据源的类型。常用类型如下:

  • odps
  • mysql
  • rds
  • oss
  • sqlserver
  • polardb
  • oracle
  • mongodb
  • emr
  • postgresql
  • analyticdb_for_mysql
  • hybriddb_for_postgresql
  • holo
EnvType Integer 1

数据源所属的环境,包括0(开发环境)和1(生产环境)。

Name String abc

数据源的名称。

ProjectId Long 1

数据源所在的DataWorks工作空间ID。您可以通过ListProjects接口获取工作空间ID。

RegionId String cn-shanghai

数据源所在的地域。例如,华东2(上海)为cn-shanghai,华北3(张家口)为cn-zhangjiakou。您无需填写RegionId,会根据调用的Endpoint自动解析。

Description String abc

数据源的描述信息。

SubType String mysql

数据源的子类型。仅当DataSourceType参数配置为rds时,该参数生效。

当DataSourceType参数配置为rds时,该参数可以配置为mysql、sqlserver或postgresql。

返回数据

名称 类型 示例值 描述
Data Long 123

数据源ID。

HttpStatusCode String 200

HTTP状态码。

RequestId String 0bc141151593763****

请求ID。

Success Boolean true

请求是否成功。

示例

请求示例

http(s)://[Endpoint]/?Action=CreateDataSource
&Content={"database":"dbname","instanceName":"instancename","password":"password","rdsOwnerId":"123","username":"username"}
&DataSourceType=rds
&EnvType=1
&Name=abc
&ProjectId=1
&RegionId=cn-shanghai
&<公共请求参数>

正常返回示例

XML格式

<RequestId>0bc141151593763****</RequestId>
<HttpStatusCode>200</HttpStatusCode>
<Data>123</Data>
<Success>true</Success>

JSON格式

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

错误码

HttpCode 错误码 错误信息 描述
400 Invalid.Tenant.ConnectionNotExists The connection does not exist. 数据源不存在。
400 Invalid.Tenant.ProjectNotExists The project does not exist. 项目不存在。
403 Invalid.Tenant.UserIsNotProjectOwnerOrAdmin The user is not a project administrator or owner. 用户不是项目负责人或者项目管理员。
400 Invalid.Tenant.UserNotInProject The user is not in the project. 用户不在项目中。
403 Invalid.Tenant.UserNotInTenant The user is not in tenant. 用户不在租户中。
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. odps类型数据源的计算引擎id和连接串信息不能同时为空。
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. 数据源类型不存在。

访问错误中心查看更多错误码。