# create\_layer 方法

## 简要

创建一个新层或已存在层的新版本。

```python
def create_layer(self,
    region_id: str,
    layer_name: str,
    layer_description: str,
    layer_content: LayerContent,
    layer_runtimes: list,
    layer_license: str = None
) -> int
```

## 参数

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

| 参数                 | 类型                                                                                                                           | 必选 | 描述                                                                                                    |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------- | -- | ----------------------------------------------------------------------------------------------------- |
| region\_id         | str                                                                                                                          | 是  | <p>创建层的数据中心唯一标识符。</p><p>例如：<code>ap-shanghai</code></p>                                               |
| layer\_name        | str                                                                                                                          | 是  | <p>创建的层的唯一名称。</p><p>例如：<code>default</code></p>                                                       |
| layer\_description | str                                                                                                                          | 是  | <p>创建的层的描述正文。</p><p>例如：<code>default layer</code></p>                                                 |
| layer\_content     | [LayerContent](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/layer-content) | 是  | <p>包含创建的层的数据的 LayerContent 实例。</p><p>例如：<code>LayerContent().use\_local\_zip\_archive(...)</code></p> |
| layer\_runtimes    | list                                                                                                                         | 是  | <p>包含创建的层兼容的无服务器云函数运行时名称的列表实例。</p><p>例如：<code>\[ FunctionRuntime.Python ]</code></p>                  |
| layer\_license     | str                                                                                                                          | 否  | <p>创建的层的许可正文。</p><p>例如：<code>default license</code></p>                                               |

## 返回值

该方法返回可等待操作对象，这将允许您等待层或层版本资源真正地创建完成。返回的可等待对操作对象包含操作结果，其指示新创建的层或层版本的版本编号。

{% 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
layer_version: int = functions_client.create_layer(
    region_id = 'ap-shanghai',
    layer_name = 'default',
    layer_description = 'default layer',
    layer_content = functions.LayerContent().use_local_zip_archive(
        local_file_path = './layer-data.zip'
    ),
    layer_runtimes = [
        functions.FunctionRuntime.Python,
        functions.FunctionRuntime.Java
    ],
    layer_license = 'default license'
).result
```

## 适用于

#### 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-layer.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.
