CreateAccount

Updated at:

Creates a database account for a specified ApsaraDB for MongoDB instance and grants one or more database role permissions to the account.

Operation description

  • Supports cloud disk and local disk instances, and supports replica set and sharded cluster architectures.

  • Accounts use a non-persistent architecture, and account information is read from the instance in real time. During the transition period before an account is created, the account does not appear in the DescribeAccounts list. After the account is created, it directly appears in the Available state.

  • The combination of account name and database name (DBName) must be unique within the same instance. Creating a duplicate account is rejected.

  • The account name cannot use the system reserved name root (case-insensitive) or the reserved prefix __cloud.

  • The requirement for Roles depends on the instance architecture: it is required for replica set and sharded cluster ConfigServer (cs) accounts. It is prohibited for sharded cluster Shard direct connection (db) accounts (passing it returns InvalidRoles.NotSupported).

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

dds:CreateAccount

create

*DBInstance

acs:dds:{#regionId}:{#accountId}:dbinstance/{#dbInstanceId}

None None

Request parameters

Parameter

Type

Required

Description

Example

DBInstanceId

string

Yes

The instance ID. For a sharded cluster instance, specify the sharded cluster ID. Account operations are executed from the perspective of the ConfigServer.

dds-uf6e9433e955xxxx

AccountName

string

Yes

The account name.

  • Regular expression: ^[a-z]+[a-z0-9|_]*[a-z0-9]+$. The name must start with a lowercase letter, end with a lowercase letter or digit, and can contain lowercase letters, digits, and underscores (_). The length must be 2 to 16 characters.

  • The reserved name root (case-insensitive, built-in system account) cannot be used.

  • The name cannot start with __cloud (reserved prefix for system accounts).

  • If the name is invalid, InvalidAccountName.Malformed is returned.

admin1

AccountPassword

string

Yes

The account password.

  • The length must be 8 to 32 characters. It can contain uppercase letters, lowercase letters, digits, and the following special characters: !@#$%^&*()_+-=.

  • The password must contain at least three of the following four character types: uppercase letters, lowercase letters, digits, and special characters.

  • If the password is invalid, InvalidAccountPassword.Malformed is returned.

Test123456!

CharacterType

string

No

The account type.
Valid values:
- normal: replica set account. For a replica set instance, any value is processed as normal.
- cs: sharded cluster ConfigServer account.
- db: sharded cluster Shard direct connection account. For a sharded cluster instance, any value other than cs is processed as db.
Default value: db.













Valid values:

  • cs :

    Sharded cluster ConfigServer account.

  • normal :

    Replica set database account.

  • db :

    Sharded cluster Shard direct connection account.

db

Roles

array<object>

No

The list of authorization roles for the account. Required for replica set and ConfigServer (cs) accounts. Prohibited for sharded cluster Shard direct connection (db) accounts.

  • Globally prohibited (returns InvalidRoles.NotAllowed): root, clusterAdmin, hostManager, clusterManager, __system, __queryableBackup, and restore.

  • Can be authorized to any database (including admin): read, userAdmin, and enableSharding.

  • Can only be authorized to non-admin databases (returns InvalidRoles.InvalidDB if authorized to admin): readWrite, dbAdmin, and dbOwner.

  • Can only be authorized to the admin database: readAnyDatabase, readWriteAnyDatabase, userAdminAnyDatabase, dbAdminAnyDatabase, clusterMonitor, backup, and alibabaCloudAdmin. (alibabaCloudAdmin is supported only for instances with kernel version 4.4 or later. For earlier versions, InvalidRoles.NotAllowed is returned.)

  • Custom roles: Roles other than the preceding ones are considered custom roles and must already exist in the instance (you can query them by calling DescribeAccountRoles). Otherwise, InvalidRoles.NotFound is returned. Roles.N.DBName must be the same as the database where the role is defined. Otherwise, InvalidRoles.DBNotMatch is returned.

  • If Roles is missing as a whole, MissingRoles is returned. If Roles.N.Role and Roles.N.DBName do not appear in pairs, InvalidRoles.Malformed is returned. If Roles is passed for a sharded cluster Shard direct connection account, InvalidRoles.NotSupported is returned.

object

No

The authorized role.

DBName

string

No

The database to which the account belongs (authentication database).
Default value: admin.
Rules: If this parameter is left empty, the request is allowed and the downstream system processes it as admin. If this parameter is specified, the length must be 1 to 63 characters. The value cannot contain /, \, ., spaces, ", or $, and cannot be local. Otherwise, InvalidParameter is returned.




admin

Role

string

No

The role name. It can be a built-in role or a custom role created on the instance. For value rules, see Roles parameter description.

read

DBName

string

No

The database to which the account belongs (authentication database).
Default value: admin.
Rules: If this parameter is left empty, the request is allowed and the downstream system processes it as admin. If this parameter is specified, the length must be 1 to 63 characters. The value cannot contain /, \, ., spaces, ", or $, and cannot be local. Otherwise, InvalidParameter is returned.




admin

AccountDescription

string

No

The account description.

  • Regular expression: ^[a-zA-Z 一-龥][a-zA-Z 一-龥 0-9_.-]{1,255}$. The description must start with an English letter or Chinese character, followed by English letters, Chinese characters, digits, underscores (_), periods (.), or hyphens (-). The length must be 2 to 256 characters.

  • If the description is invalid, InvalidAccountDescription.Malformed is returned.

test

Response elements

Element

Type

Description

Example

object

RequestId

string

The request ID.

7FEF1BEF-2842-5758-9126-415A297XXXXX

TaskId

integer

The task ID.

123456

Examples

Success response

JSON format

{
  "RequestId": "7FEF1BEF-2842-5758-9126-415A297XXXXX",
  "TaskId": 123456
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidAccountName.Malformed Specified parameter AccountName is not valid. The specified AccountName parameter is invalid.
400 InvalidAccountPassword.Malformed Specified parameter AccountPassword is not valid. The specified parameter AccountPassword is invalid.
400 InvalidAccountDescription.Malformed Specified parameter AccountDescription is not valid. The specified AccountDescription parameter is invalid.
404 AccountLimitExceeded AccountQuotaExceeded: Exceeding the allowed amount of account.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.