Creates a data source in DataWorks.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CreateDataSource

The operation that you want to perform. Set the value to CreateDataSource.

RegionId String Yes cn-shanghai

The region ID of the data source. For example, the ID of the China (Shanghai) region is cn-shanghai, and the ID of the China (Zhangjiakou) region is cn-zhangjiakou. The system determines the value of this parameter based on the endpoint that is used to call the operation.

ProjectId Long Yes 1

The ID of the DataWorks workspace to which the data source belongs. You can call the ListProjects operation to obtain the ID.

Name String Yes abc

The name of the data source.

Description String No abc

The description of the data source.

DataSourceType String Yes rds

The type of the data source. Valid values:

  • odps
  • mysql
  • rds
  • oss
  • sqlserver
  • polardb
  • oracle
  • mongodb
  • emr
  • postgresql
  • analyticdb_for_mysql
  • hybriddb_for_postgresql
  • holo
SubType String No mysql

The subtype of the data source. This parameter takes effect only when the DataSourceType parameter is set to mysql.

If the DataSourceType parameter is set to mysql, this parameter can be set to RDS, sqlserver, or postgresql.

EnvType Integer Yes 1

The environment in which the data source is used. Valid values: 0 and 1. 0 indicates the development environment. 1 indicates the production environment.

Content String Yes null

The details of the data source. Examples of details of some common data sources:

  • 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"
}
                                

Response parameters

Parameter Type Example Description
HttpStatusCode String 200

The HTTP status code returned.

Data Long 123

The ID of the data source.

RequestId String 0bc141151593763****

The ID of the request.

Success Boolean true

Indicates whether the request is successful.

Examples

Sample requests

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
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

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

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

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

Error codes

HttpCode Error code Error message Description
400 Invalid.Tenant.ConnectionNotExists The connection does not exist. The error message returned because the specified data source does not exist.
400 Invalid.Tenant.ProjectNotExists The project does not exist. The error message returned because the specified workspace does not exist.
400 Invalid.Tenant.UserNotInProject The user is not in the project. The error message returned because the user is not added to the workspace.
400 ConnectionAlreadyExist The connection with envType %s and name %s already exists. The error message returned because the connection string already exists.
400 DataSource.CheckRamRoleFailure Failed to check the RAM role. AccountId %s. roleArn %s. The error message returned because the permissions on the data source failed to be verified.
400 DataSource.ConnectionStrProperty.PatternNotMatch The pattern value %s is invalid. The correct pattern is %s. The error message returned because the connection string property of the data source does not match the specified rules.
400 Invalid.DataSource.DataSourceTypeNotSupport The dataSourceType %s and subType %s are not supported. The error message returned because the data source type is not supported.
400 MissingParam.ConnectionStr.Property You must specify property %s required by the data source connection string. The error message returned because the required properties of the connection string of the data source are not specified.
400 Invalid.DataSource.DataSourceTypeNotExist The data source type %s does not exist. The error message returned because the specified data source type does not exist.
403 Invalid.Tenant.UserIsNotProjectOwnerOrAdmin The user is not a project administrator or owner. The error message returned because the user is not the workspace owner or administrator.
403 Invalid.Tenant.UserNotInTenant The user is not in tenant. The error message returned because the user does not belong to the tenant.

For a list of error codes, visit the API Error Center.