# create\_function 方法

## 简要

调用给定无服务器云函数并获得无服务器云函数的运行结果。

```python
def create_function(self,
    region_id: str,
    namespace_name: str,
    function_name: str,
    function_description: str,
    function_code: FunctionCode,
    function_runtime: str = 'Python3',
    function_type: str = None,
    function_configure: dict = None
)
```

## 参数

该方法的参数和参数描述如下：

| 参数                    | 类型                                                                                                                               | 必选 | 描述                                                                                                                                                                                      |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| region\_id            | str                                                                                                                              | 是  | 创建的无服务器云函数所在数据中心的唯一标识符。                                                                                                                                                                 |
| namespace\_name       | str                                                                                                                              | 是  | 创建的无服务器云函数所在命名空间的名称。                                                                                                                                                                    |
| function\_name        | str                                                                                                                              | 是  | 创建的无服务器云函数名称。                                                                                                                                                                           |
| function\_description | str                                                                                                                              | 否  | 创建的无服务器云函数描述正文。                                                                                                                                                                         |
| function\_code        | [FunctionCode](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/function-code)     | 是  | 创建的无服务器云函数代码实例。                                                                                                                                                                         |
| function\_runtime     | str                                                                                                                              | 否  | 创建的无服务器云函数运行时名称。如果该参数被忽略，默认运行时为 `Python3`。建议使用 [FunctionRuntime](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/data-types/function-runtime-enum) 枚举器成员。 |
| function\_type        | str                                                                                                                              | 否  | 创建的无服务器云函数类型。如果该参数被忽略，默认类型为 `Event`。建议使用 [FunctionType](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/data-types/function-type-enum) 枚举器成员。             |
| function\_configure   | [FunctionConfigure](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/data-types/function-configure) | 否  | 创建的无服务器云函数配置。如果该参数被忽略或设置为 `None`，被创建的函数将采用默认配置。                                                                                                                                         |

## 返回值

该方法返回可等待操作对象，这将允许您等待无服务器云函数资源真正地创建完成。

{% content-ref url="/pages/-M4ET-juBkynutmGcsq8" %}
[Waitable 类](/tencent-cloud-sdk/python-docs/other-products/class-and-method/waitable.md)
{% endcontent-ref %}

### 兼容性

在 Tencent Cloud SDK for Python 0.1.6 或更低版本中，该方法没有返回值。

## 异常

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

#### ValueError

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

#### ActionError

Tencent Cloud API 错误。例如访问凭据无效、给定无服务器云函数不存在等均会引发该异常。

## 示例

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

```python
function_client.create_function(
    region_id = 'ap-shanghai',
    namespace_name = 'default',
    function_name = 'addend',
    function_description = 'Addition function'，
    function_code = functions.FunctionCode().use_object_storage_bucket(
        region_id = 'ap-shanghai-1',
        bucket_id = 'scf-code',
        object_name = 'source.zip'
    ),
    function_runtime = functions.FunctionRuntime.Python,
    function_type = functions.FunctionType.Event,
    function_configure = {
        'handler': 'index.main',
        'memory_size': 128,
        'time_out': 3
    }
)
```

## 适用于

#### Tencent Cloud SDK for Python

产品软件包：tencent-cloud-sdk-serverless-functions >= 0.1.6


---

# 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-functions/class-and-method/client/create-function.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.
