Updated on 2024-09-04 GMT+08:00

Creating a DB Instance

Function

This API is used to create a single-node or primary/standby FlexusRDS instance.

This API allows you to set the X-Client-Token request header in the HTTP request header when you create a FlexusRDS instance, to ensure the request idempotence. For details, see Idempotent Requests.

URI

  • URI format

    POST /v3/{project_id}/instances

  • Parameter description
    Table 1 Parameters

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

    Explanation:

    Project ID of a tenant in a region.

    For details about how to obtain the project ID, see Obtaining a Project ID.

    Constraints:

    N/A

    Value range:

    N/A

    Default value:

    N/A

Request

Table 2 Parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Explanation:

Instance name.

Constraints:

Instances of the same type can have the same name under the same tenant.

Value range:

The instance name must start with a letter and consist of 4 to 64 characters. Only letters (case-sensitive), digits, hyphens (-), underscores (_), and periods (.) are allowed.

Default value:

N/A

datastore

Yes

Object

Explanation:

Database information.

For details, see Table 3.

Constraints:

N/A

flavor_ref

Yes

String

Explanation:

Specification code.

Constraints:

N/A

Value range:

The value cannot be empty. For details, see spec_code in Table 3 of Querying Database Specifications.

Default value:

N/A

volume

Yes

Object

Explanation:

Instance storage. For details, see Table 6.

Constraints:

N/A

region

Yes

String

Explanation:

Region ID.

Constraints:

N/A

Value range:

The value cannot be empty. For details, see Regions and Endpoints.

Default value:

N/A

availability_zone

Yes

String

Explanation:

AZ ID.

Constraints:

If the DB instance is not a single-node instance, you need to specify an AZ for each node of the instance and separate the AZs with commas (,).

Value range:

The value cannot be empty. For details, see Regions and Endpoints.

Default value:

N/A

ha

No

Object

Explanation:

HA configuration. For details, see Table 4.

Constraints:

This parameter is used only when you create a primary/standby instance.

port

No

String

Explanation:

Database port.

Constraints:

N/A

Value range:

  • If this parameter is not specified, the default value is 3306.
  • If this parameter is specified, the value range is from 1024 to 65535 (excluding 12017 and 33071, which are occupied by the RDS system and cannot be used).

Default value:

3306

password

No

String

Explanation:

Database password.

Constraints:

You are advised to enter a strong password to improve security, preventing security risks such as brute force cracking. If the password you provide is regarded as a weak password by the system, you will be prompted to enter a stronger password.

Value range:

A database password must be 8 to 32 characters long and contain at least three types of the following characters: uppercase letters, lowercase letters, digits, and special characters. The allowed special characters include ~!@#$%^*-_=+?,()&.

Default value:

N/A

backup_strategy

No

Object

Explanation:

Advanced backup policy. For details, see Table 5.

Constraints:

N/A

charge_info

Yes

Object

Explanation:

Yearly/Monthly billing information. For details, see Table 7.

Constraints:

N/A

time_zone

No

String

Explanation:

UTC time zone.

Constraints:

N/A

Value range:

  • If this parameter is not specified, the UTC time is used by default.
  • If this parameter is specified, the value range is from UTC-12:00 to UTC+12:00 on the hour. For example, the value can be UTC+08:00 rather than UTC+08:30.

Default value:

UTC+08:00

tags

No

Array of objects

Explanation:

Tag list. Each DB instance can be associated with tag key-value pairs while being created.

For details, see Table 8.

Constraints:

If you want to create DB instances with multiple tag key-value pairs, separate them with commas (,). A maximum of 20 key-value pairs can be added for an instance.

is_flexus

Yes

boolean

Explanation:

Whether to create a FlexusRDS instance.

Constraints:

N/A

Value range:

true

Default value:

N/A

Table 3 datastore field data structure description

Parameter

Mandatory

Type

Description

type

Yes

String

Explanation:

DB engine.

Constraints:

N/A

Value range:

MySQL

Default value:

N/A

version

Yes

String

Explanation:

DB engine version.

Constraints:

N/A

Value range:

5.7 or 8.0

Default value:

N/A

Table 4 ha field data structure description

Parameter

Mandatory

Type

Description

mode

Yes

String

Explanation:

Instance type.

Constraints:

N/A

Value range:

HA (case-insensitive)

Default value:

N/A

replication_mode

Yes

String

Explanation:

Replication mode for the standby instance.

Constraints:

N/A

Value range:

  • async: asynchronous replication
  • semisync: semi-synchronous replication

Default value:

N/A

Table 5 backup_strategy field data structure description

Parameter

Mandatory

Type

Description

start_time

Yes

String

Explanation:

Backup time window. Automated backups will be triggered during the backup time window.

Constraints:

N/A

Value range:

The value cannot be empty. It must be a valid value in the "hh:mm-HH:MM" format. The current time is the UTC time.

  • The HH value must be 1 greater than the hh value.
  • The values of mm and MM must be the same and must be set to 00, 15, 30, or 45.

Example:

  • 08:15-09:15
  • 23:00-00:00

Default value:

N/A

keep_days

No

Integer

Explanation:

Retention days for backups.

Constraints:

N/A

Value range:

  • If this parameter is not specified, the default value 7 is used.
  • If this parameter is specified, the value range is from 0 to 732. 0 indicates that the automated backup policy is disabled. To extend the retention period, contact customer service. Automated backups can be retained for up to 2,562 days.

Default value:

7

Table 6 volume field data structure description

Parameter

Mandatory

Type

Description

type

Yes

String

Explanation:

Storage type.

Constraints:

N/A

Value range:

CLOUDSSD (case-sensitive): cloud SSD storage. This storage type is supported only with general-purpose and dedicated instances.

Default value:

N/A

size

Yes

Integer

Explanation:

Storage space.

Constraints:

N/A

Value range:

40–4000, in GB. The value must be a multiple of 10.

Default value:

N/A

Table 7 charge_info field data structure description

Parameter

Mandatory

Type

Description

charge_mode

Yes

String

Explanation:

Billing mode.

Constraints:

N/A

Value range:

prePaid: indicates the yearly/monthly billing mode.

Default value:

N/A

period_type

Yes

String

Explanation:

Subscription type.

Constraints:

N/A

Value range:

  • month: indicates that the subscription unit is month.
  • year: indicates that the subscription unit is year.

Default value:

N/A

period_num

Yes

Integer

Explanation:

Subscription period.

Constraints:

N/A

Value range:

  • When period_type is set to month, the parameter value ranges from 1 to 9.
  • When period_type is set to year, the parameter value ranges from 1 to 3.

Default value:

N/A

is_auto_renew

No

boolean

Explanation:

Whether automatic renewal is enabled for yearly/monthly instances. The renewal period is the same as the original period, and the order will be automatically paid.

Constraints:

N/A

Value range:

  • true: indicates that automatic renewal is enabled.
  • false: indicates that automatic renewal is disabled. The default value is false.

Default value:

false

is_auto_pay

No

boolean

Explanation:

Whether the order will be automatically paid. This parameter does not affect the payment method of automatic renewal.

Constraints:

N/A

Value range:

  • true: indicates the order will be automatically paid.
  • false: indicates the order will be manually paid. The default value is false.

Default value:

false

Table 8 tags field data structure description

Parameter

Mandatory

Type

Description

key

Yes

String

Explanation:

Tag key.

Constraints:

N/A

Value range:

It must consist of 1 to 128 Unicode characters.

It can contain letters, digits, spaces, and special characters _.:=+-@. However, it cannot start or end with a space, or start with _sys_.

Default value:

N/A

value

Yes

String

Explanation:

Tag value.

Constraints:

N/A

Value range:

It can be left blank or contain a maximum of 255 Unicode characters.

It can contain letters, digits, spaces, and special characters _.:=+-@.

Default value:

N/A

Example Request

The values of region and availability_zone in the example request are only for reference.

  • Create a single-node FlexusRDS instance.
    POST https://{endpoint}/v3/0483b6b16e954cb88930a360d2c4e663/instances
    
    {
    	"name": "flexusrds-instance",
    	"datastore": {
    		"type": "MySQL",
    		"version": "5.7"
    	},
    	"flavor_ref": "rds.mysql.y1.large.2",
    	"volume": {
    		"type": "CLOUDSSD",
    		"size": 100
    	},
    	"region": "aaa",
    	"availability_zone": "bbb",
    	"port": 3306,
    	"backup_strategy": {
    		"start_time": "08:15-09:15",
    		"keep_days": 12
    	},
    	"charge_info": {
    		"charge_mode": "prePaid"
    	},
    	"password": "****",
    	"time_zone": "UTC+04:00",
    	"tags": [
    		{
    			"key": "key1",
    			"value": "value1"
    		},
    		{
    			"key": "key2",
    			"value": "value2"
    		}
    	],
    	"is_flexus": true
    }
  • Create a primary/standby FlexusRDS instance.
    {
    	"name": "flexusrds-instance-ha",
    	"datastore": {
    		"type": "MySQL",
    		"version": "5.7"
    	},
    	"ha": {
    		"mode": "ha",
    		"replication_mode": "semisync"
    	},
    	"flavor_ref": "rds.mysql.y1.xlarge.2.ha",
    	"volume": {
    		"type": "CLOUDSSD",
    		"size": 100
    	},
    	"region": "aaa",
    	"availability_zone": "bbb",
    	"port": 3306,
    	"backup_strategy": {
    		"start_time": "08:15-09:15",
    		"keep_days": 12
    	},
    	"charge_info": {
    		"charge_mode": "prePaid"
    	},
    	"password": "****",
           "tags": [
    		{
    			"key": "key1",
    			"value": "value1"
    		},
    		{
    			"key": "key2",
    			"value": "value2"
    		}
    	],
    	"is_flexus": true
    }

Response

  • Normal response
    Table 9 Parameters

    Parameter

    Type

    Description

    instance

    Object

    Explanation:

    Instance information. For details, see Table 10.

    order_id

    String

    Explanation:

    Order ID.

    Value range:

    N/A

    Table 10 instance field data structure description

    Parameter

    Type

    Description

    id

    String

    Explanation:

    Instance ID.

    Value range:

    N/A

    name

    String

    Explanation:

    Instance name. Instances of the same type can have the same name under the same tenant.

    Value range:

    The value is the same as that of the corresponding request parameter.

    status

    String

    Explanation:

    Instance status.

    Value range:

    BUILD: indicates that the instance is being created.

    datastore

    Object

    Explanation:

    Database information. For details, see Table 11.

    ha

    Object

    Explanation:

    HA configuration. This parameter is returned only when primary/standby instances are created.

    For details, see Table 12.

    port

    String

    Explanation:

    Database port.

    Value range:

    The value is the same as that of the corresponding request parameter.

    backup_strategy

    Object

    Explanation:

    Automated backup policy. For details, see Table 13.

    flavor_ref

    String

    Explanation:

    Specification code.

    Value range:

    The value is the same as that of the corresponding request parameter.

    volume

    Object

    Explanation:

    Volume information. For details, see Table 14.

    region

    String

    Explanation:

    Region ID.

    Value range:

    The value is the same as that of the corresponding request parameter.

    availability_zone

    String

    Explanation:

    AZ ID.

    Value range:

    The value is the same as that of the corresponding request parameter.

    vpc_id

    String

    Explanation:

    VPC ID.

    Value range:

    vpc-default-smb

    subnet_id

    String

    Explanation:

    Subnet ID.

    Value range:

    subnet-default-smb

    security_group_id

    String

    Explanation:

    Security group which the instance is associated with.

    Value range:

    sg-default-smb

    charge_info

    Object

    Explanation:

    Billing information. For details, see Table 15.

    Table 11 datastore field data structure description

    Parameter

    Type

    Description

    type

    String

    Explanation:

    DB engine.

    Value range:

    MySQL

    version

    String

    Explanation:

    DB engine version.

    Value range:

    5.7 or 8.0

    Table 12 ha field data structure description

    Parameter

    Type

    Description

    mode

    String

    Explanation:

    Instance type.

    Value range:

    HA (case-insensitive)

    replication_mode

    String

    Explanation:

    Replication mode for the standby instance.

    Value range:

    • async: asynchronous replication
    • semisync: semi-synchronous replication
    Table 13 backupStrategy field data structure description

    Parameter

    Type

    Description

    start_time

    String

    Explanation:

    Backup time window. Automated backups will be triggered during the backup time window.

    Value range:

    The value cannot be empty. It must be a valid value in the "hh:mm-HH:MM" format. The current time is the UTC time.

    • The HH value must be 1 greater than the hh value.
    • The values of mm and MM must be the same and must be set to 00, 15, 30, or 45.

    Example:

    • 08:15-09:15
    • 23:00-00:00

    If backup_strategy in the request body is empty, 02:00-03:00 is returned for start_time by default.

    keep_days

    Integer

    Explanation:

    Retention days for backups.

    Value range:

    0–732. 0 indicates that the automated backup policy is disabled. To extend the retention period, contact customer service. Automated backups can be retained for up to 2,562 days.

    If backup_strategy in the request body is empty, 7 is returned for keep_days by default.

    Table 14 volume field data structure description

    Parameter

    Type

    Description

    type

    String

    Explanation:

    Storage type.

    Value range:

    CLOUDSSD (case-sensitive): cloud SSD storage. This storage type is supported only with general-purpose and dedicated instances.

    size

    Integer

    Explanation:

    Storage space.

    Value range:

    40–4000, in GB. The value must be a multiple of 10.

    Table 15 chargeInfo field data structure description

    Parameter

    Type

    Description

    charge_mode

    String

    Explanation:

    Billing mode.

    Value range:

    prePaid: indicates the yearly/monthly billing mode.

    period_num

    Integer

    Explanation:

    Subscription period.

    Value range:

    The value is the same as that of the corresponding request parameter.

The values of region and availability_zone in the example response are only for reference.

  • Example normal response

    Single-node FlexusRDS instance created.

    {
    	"instance": {
    		"id": "dsfae23fsfdsae3435in01",
    		"name": "flexusrds-instance",
    		"datastore": {
    			"type": "MySQL",
    			"version": "5.7"
    		},
    		"flavor_ref": "rds.mysql.y1.large.2",
    		"volume": {
    			"type": "CLOUDSSD",
    			"size": 100
    		},
                    "region": "aaa",
    		"availability_zone": "bbb",
    		"vpc_id": "490a4a08-ef4b-44c5-94be-3051ef9e4fce",
    		"subnet_id": "0e2eda62-1d42-4d64-a9d1-4e9aa9cd994f",
    		"security_group_id": "2a1f7fc8-3307-42a7-aa6f-42c8b9b8f8c5",
    		"port": "3306",
    		"backup_strategy": {
    			"start_time": "08:15-09:15",
    			"keep_days": 3
    		},
    		"charge_info": {
    			"charge_mode": "postPaid"
    		}
    	},
    	"job_id": "dff1d289-4d03-4942-8b9f-463ea07c000d"
    }

    Primary/standby FlexusRDS instance created.

    {
      "instance":{ 
               "id": "dsfae23fsfdsae3435in01",
               "name": "flexusrds-instance-ha", 
               "datastore": { 
                 "type": "MySQL", 
                 "version": "5.7" 
                }, 
               "ha": {
                 "mode": "ha",
                 "replication_mode": "semisync"
               },
               "flavor_ref": "rds.mysql.y1.xlarge.2.ha",
               "volume": { 
                   "type": "CLOUDSSD", 
                   "size": 100 
                 },
               "region": "aaa",
               "availability_zone": "bbb,ccc",
               "vpc_id": "490a4a08-ef4b-44c5-94be-3051ef9e4fce", 
               "subnet_id": "0e2eda62-1d42-4d64-a9d1-4e9aa9cd994f",
               "security_group_id": "2a1f7fc8-3307-42a7-aa6f-42c8b9b8f8c5", 
               "port": "3306", 
               "backup_strategy": { 
                 "start_time": "08:15-09:15", 
                 "keep_days": 3 
                }, 
               "charge_info": {
                       "charge_mode": "postPaid"
                                   },
             },
      "job_id": "dff1d289-4d03-4942-8b9f-463ea07c000d" 
    }
  • Abnormal response

    For details, see Abnormal Request Results.

Status Code