# create\_instance 方法

## 简要

创建一个新的无服务器数据库实例。

```python
def create_instance(self,
    region_id: str,
    zone_id: str,
    instance_name: str,
    instance_configure: dict = None
) -> dict
```

## 参数

该方法具有以下参数，其参数名、参数类型和参数描述如下：

| 参数                  | 类型                                                                                                                              | 必选 | 描述                                                        |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------- | -- | --------------------------------------------------------- |
| region\_id          | str                                                                                                                             | 是  | <p>创建的无服务器数据库实例目的数据中心园区唯一标识符。</p><p>例如：ap-shanghai</p>    |
| zone\_id            | str                                                                                                                             | 是  | <p>创建的无服务器数据库实例目的数据中心可用区唯一标识符。</p><p>例如：ap-shanghai-2</p> |
| instance\_name      | str                                                                                                                             | 是  | <p>创建的无服务器数据库实例名称。</p><p>例如：default</p>                   |
| instance\_configure | [InstanceConfigure](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-database/data-types/instance-configure) | 否  | 创建的无服务器数据库实例配置。                                           |

## 返回值

该方法返回包含创建的无服务器数据库实例元数据信息的字典实例，其数据类型为 [InstanceInfo](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-database/data-types/instance-info)。

{% hint style="info" %}
请注意，受限于 Tencent Cloud API，该方法目前仅支持返回实例 ID。
{% endhint %}

## 异常

该方法可能会主动引发以下异常类型：

#### ValueError

参数值或类型不符合预期。

## 示例

接下来我们将通过一段 Python 代码向您演示如何使用该方法：

```python
instance_info: dict = client.create_instance(
    region_id = 'ap-shanghai',
    zone_id = 'ap-shanghai-2',
    instance_name = 'unit-test',
    instance_configure = {
        'database': {
            'version': '10.4',
            'charset': database.DatabaseCharset.UTF8
        },
        'vpc': {
            'id': 'vpc-f7qfb64q',
            'subnet_id': 'subnet-aieh8myj'
        }
    }
)

# 请注意，目前字典 instance_info 仅包含成员 'id'。

print(instance_info['id'])
```

## 适用于

#### Tencent Cloud SDK for Python

基础软件包：tencent-cloud-sdk-serverless-database >= 0.1.1


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-database/class-and-method/client/create-instance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
