> For the complete documentation index, see [llms.txt](https://smallso.gitbook.io/tencent-cloud-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/client/invoke.md).

# invoke 方法

## 简要

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

```python
def invoke(self,
    region_id: str,
    namespace_name: str,
    function_name: str,
    function_event: dict = None,
    function_version: str = None,
    function_async: bool = False
) -> dict
```

## 参数

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

| 参数                | 类型   | 必选 | 描述                                                                           |
| ----------------- | ---- | -- | ---------------------------------------------------------------------------- |
| region\_id        | str  | 是  | 调用的无服务器云函数所在数据中心的唯一标识符。                                                      |
| namespace\_name   | str  | 是  | 调用的无服务器云函数所在命名空间的名称。                                                         |
| function\_name    | str  | 是  | 调用的无服务器云函数名称。                                                                |
| function\_event   | dict | 否  | <p>调用的无服务器云函数事件。</p><p>如果该参数被忽略或设置为 <code>None</code>，默认传递空事件。</p>           |
| function\_version | str  | 否  | <p>调用的无服务器云函数版本名称。</p><p>如果该参数被忽略或设置为 <code>None</code>，默认调用最新版本。</p>        |
| function\_async   | bool | 否  | <p>调用的无服务器云函数是否以异步的方式运行。</p><p>如果该参数被忽略或设置为 <code>None</code>，默认以同步方式运行。</p> |

## 返回值

返回包含给定无服务器云函数运行结果的字典实例，其数据类型为 [FunctionResult](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/data-types/function-result)。

## 异常

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

#### ValueError

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

#### InvokeError

给定无服务器云函数在调用过程中遇到错误，这通常是由于无服务器云函数所运行的代码存在异常。

#### ActionError

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

#### ActionResultError

Tencent Cloud API 返回结果是非预期的，该异常通常情况下不会引发。

## 示例

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

```python
return_result: str = function_client.invoke(
    region_id = 'ap-shanghai',
    namespace_name = 'default',
    function_name = 'addend',
    function_event = {
        'value1': 10,
        'value2': 20
    },
    function_version = '1',
    function_async = False
)
```

## 适用于

#### Tencent Cloud SDK for Python

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