Adds 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.

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

The details of the data source. Example:

  • MaxCompute

{
  "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"
}
  • ApsaraDB RDS

{
  "configType": 1,
  "tag": "rds",
  "database": "xsaxsa",
  "username": "xsaxsa",
  "password": "xssaxsa$32050",
  "instanceName": "rm-xsaxs",
  "rdsOwnerId": "11111111"
}
  • Object Storage Service (OSS)

{
  "accessId": "sssssxx",
  "accessKey": "xsaxaxsaxs",
  "bucket": "xsa-xs-xs",
  "endpoint": "http://oss-cn-shanghai.aliyuncs.com",
  "tag": "public"
}
  • SQL Server

{
  "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"
}
  • E-MapReduce (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"
}
  • Hologres

{
  "accessId": "xsaxsaxs",
  "accessKey": "xsaxsaxsa",
  "database": "xsaxsaxsa",
  "instanceId": "xsaxa",
  "tag": "aliyun"
}
  • Kafka

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

The type of the data source. Valid values:

  • MaxCompute
  • MySQL
  • ApsaraDB RDS
  • Object Storage Service (OSS)
  • SQL Server
  • PolarDB
  • Oracle
  • MongoDB
  • E-MapReduce (EMR)
  • PostgreSQL
  • AnalyticDB for MySQL
  • HybridDB for PostgreSQL
  • Hologres
EnvType Integer Yes 1

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

Name String Yes abc

The name of the data source.

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.

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 that of the China (Zhangjiakou) region is cn-zhangjiakou. The system automatically determines the value of this parameter based on the endpoint used to call the operation.

Description String No abc

The description of the data source.

SubType String No MySQL

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

When the DataSourceType parameter is set to rds, this parameter can be set to mysql, sqlserver, or postgresql.

Response parameters

Parameter Type Example Description
Data Long 123

The ID of the data source.

HttpStatusCode String 200

The HTTP status code returned.

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

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

JSON format

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

Error codes

HTTP status code 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.
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.
400 Invalid.Tenant.UserNotInProject The user is not in the project. The error message returned because the user is not added to the workspace.
403 Invalid.Tenant.UserNotInTenant The user is not in tenant. The error message returned because the user does not belong to the tenant.
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 have 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 Invalid.Param.Odps.EngineIdOrConnectStrEmpty Either the compute engine ID or the connection string must be specified when data source type is ODPS. The error message returned because the compute engine instance ID or the connection string must be specified when you add a MaxCompute data source.
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 resource type does not exist.

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