> 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/copy-function.md).

# copy\_function 方法

## 简要

为给定无服务器云函数创建一个拷贝副本函数。

```python
def copy_function(self,
    region_id: str,
    namespace_name: str,
    function_name: str,
    target_region_id: str,
    target_namespace_name: str,
    target_function_name: str,
    allow_override: bool = False,
    copy_configure: bool = True
)
```

## 参数

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

| 参数                      | 类型   | 必选 | 描述                                                          |
| ----------------------- | ---- | -- | ----------------------------------------------------------- |
| region\_id              | str  | 是  | 当前无服务器云函数所在数据中心的唯一标识符。                                      |
| namespace\_name         | str  | 是  | 当前无服务器云函数所在命名空间的名称。                                         |
| function\_name          | str  | 是  | 当前无服务器云函数名称。                                                |
| target\_region\_id      | str  | 是  | 目标无服务器云函数所在数据中心的唯一标识符。                                      |
| target\_namespace\_name | str  | 是  | 目标无服务器云函数所在命名空间的名称。                                         |
| target\_function\_name  | str  | 是  | 目标无服务器云函数名称。                                                |
| allow\_override         | bool | 否  | 如果目标无服务器云函数已存在，是否允许将其覆盖。如果该参数被忽略或设置为 `None`，默认不允许覆盖。        |
| copy\_configure         | bool | 否  | 是否将当前无服务器云函数配置拷贝给目标无服务器云函数。如果该参数被忽略或设置为 `None`，默认不拷贝当前函数配置。 |

## 返回值

该方法没有返回值。

## 异常

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

#### ValueError

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

#### ActionError

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

## 示例

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

```python
function_client.copy_function(
    region_id = 'ap-shanghai',
    namespace_name = 'default',
    function_name = 'addend',
    target_region_id = 'ap-guangzhou',
    target_namespace_name = 'default',
    target_function_name = 'addend',
    allow_override = True,
    copy_configure = True
)
```

## 适用于

#### Tencent Cloud SDK for Python

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