函数计算提供了常用的公共层,您无需自定义层即可为您的函数配置层功能。本文介绍如何在函数中配置官方公共层。

函数计算支持的官方公共层

函数计算支持以下几类官方公共层。以下列出部分常用的官方公共层,关于函数计算支持的所有官方公共层及其说明,请参见公共层

如果您在使用过程中,未找到您需要的层,请联系我们为您添加。

自定义运行时

包括自定义语言的运行时,例如Python 3.10、Node.js 17等。还包括一些自定义语言运行时的依赖库集合,例如,公共层Python310-Package-Collection包含Python常用的一些依赖库。

公共层名称兼容的运行时说明使用前必读
Python310
  • Custom
  • Custom.Debian10
Python 3.10.5运行时层README.md
Python310-Package-Collection
  • Custom
  • Custom.Debian10
Python 3.10运行时的常用依赖库集合README.md
Python39
  • Custom
  • Custom.Debian10
Python 3.9.13运行时层README.md
Python39-Package-Collection
  • Custom
  • Custom.Debian10
Python 3.9运行时的常用依赖库集合README.md
Python38
  • Custom
  • Custom.Debian10
Python 3.8.13运行时层README.md
Python38-Package-Collection
  • Custom
  • Custom.Debian10
Python 3.8.13运行时的常用依赖库集合README.md
Python36CustomPython 3.6.15运行时层README.md
Python36-Package-CollectionCustomPython 3.6.15的常用依赖库集合README.md
Dotnet6CustomASP.NET 6.0.5运行时层README.md
PHP81CustomPHP 8.1运行时层README.md
PHP80CustomPHP 8.0运行时层README.md
PHP72CustomPHP 7.2运行时层README.md
Java8Custom.Debian10Java 8运行时层README.md
Java11CustomJava 11运行时层README.md
Java17CustomJava 17运行时层README.md
Nodejs18Custom.Debian10Node.js 18运行时层README.md
Nodejs17CustomNode.js 17运行时层README.md
Nodejs16
  • Custom
  • Custom.Debian10
Node.js 16运行时层README.md
Nodejs14CustomNode.js 14运行时层README.md
Nodejs12CustomNode.js 12运行时层README.md
Go118CustomGo 1.x运行时层README.md

常用依赖库

公共层名称兼容的运行时说明版本(只展示核心库的版本号)使用前必读
Python39-Pandas1x
  • Python 3.9
  • Custom
  • Custom.Debian10
一个基于NumPy的开源的数据分析和处理工具
  • pandas==1.4.3
  • numpy==1.23.2
README.md
Python39-SciPy1x
  • Python 3.9
  • Custom
一款开源的科学计算库
  • scipy==1.9.0
  • numpy==1.23.2
README.md
Python36-SciPy1x
  • Python 3.6
  • Custom
一款开源的科学计算库
  • scipy-1.5.4
  • numpy-1.19.5
README.md
Python39-PyTorch1x
  • Python 3.9
  • Custom
  • Custom.Debian10
一款开源机器学习框架(CPU版)
  • torch==1.12.1+cpu
  • torchaudio==0.12.1+cpu
  • torchvision==0.13.1+cpu
README.md
Python36-PyTorch1x
  • Python 3.6
  • Custom
一款开源机器学习框架(CPU版)
  • torch==1.10.2+cpu
  • torchaudio==0.10.2+cpu
  • torchvision==0.11.3+cpu
README.md
Python3-Flask2x
  • Python 3.9
  • Python 3.10
  • Custom
  • Custom.Debian10
一个基于Python编写的轻量级的Web框架v2.2.2README.md
Nodejs-Puppeteer17x
  • Node.js 16
  • Node.js 14
  • Custom
  • Custom.Debian10
一个Headless Chrome工具puppeteer-v17.1.0README.md
Nodejs-Puppeteer10x
  • Node.js 16
  • Node.js 14
  • Node.js 12
  • Custom
一个Headless Chrome工具puppeteer-v10.2.0README.md
Python310-Opencv4x
  • Python 3.10
  • Custom.Debian10
一个跨平台的计算机视觉库v4.7.0.68README.md
SQLite3
  • Python 3.9
  • Node.js 16
  • Node.js 14
  • Java 11
  • Java 8
  • Custom
一种轻量型、进程内的关系型数据库3.41.1README.md
FFmpeg6x
  • Python 3.10
  • Python 3.9
  • Node.js 16
  • Node.js 14
  • Java 11
  • Java 8
  • Custom
  • Custom.Debian10
一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序6.0README.md
Nodejs-Puppeteer19xCustom.Debian10一个Headless Chrome 工具puppeteer-v19.8.5README.md
Python38-PlaywrightCustom.Debian10puppeteer-v19.8.51.31.1README.md
Poppler22x-Pdf2imagePython 3.10一个用来渲染PDF文档的程序库22.12.0README.md
ServerlessDevs
  • Python 3.10
  • Python 3.9
  • Python 3
  • Node.js 16
  • Node.js 14
  • Java 11
  • Java 8
  • Go 1
  • .NetCore 3.1
  • PHP 7.2
  • Custom
  • Custom.Debian10
一个开源开放的Serverless开发者平台,致力于为开发者提供强大的工具链体系2.1.14README.md

Web框架

公共层名称兼容的运行时版本(只展示核心库的版本号)使用前必读
Python3-Flask2x
  • Python 3.9
  • Custom
flask-2.2.2README.md

阿里云SDK

公共层名称兼容的运行时说明使用前必读
Aliyun-DataX
  • Python 2.7
  • Python 3
  • Python 3.6
  • Python 3.9
  • Custom
  • Custom.Debian10
阿里云DataWorks数据集成的开源版本README.md
Python39-Aliyun-SDK
  • Python 3.9
  • Custom
阿里云常用SDK(Python3.9)README.md
Python36-Aliyun-SDK
  • Python 3.6
  • Custom
阿里云常用SDK(Python3.6)README.md
Nodejs-Aliyun-SDK
  • Node.js 16
  • Node.js 14
  • Node.js 12
  • Custom
  • Custom.Debian10
阿里云常用SDK(Node.js 16/Node.js 14/Node.js 12)README.md

通过控制台配置官方公共层

前提条件

创建函数

操作步骤

  1. 登录函数计算控制台,在左侧导航栏,单击服务及函数
  2. 在顶部菜单栏,选择地域,然后在服务列表页面,单击目标服务。
  3. 函数管理页面,单击目标函数操作列的配置
  4. 区域,单击+添加层,从下拉列表中选择添加官方公共层
  5. 官方公共层下拉列表,查看层的描述和License信息并选择一个官方公共层,在层版本下拉列表,选择层版本,然后单击保存
说明
  • 一个函数最多支持配置5个层,包括自定义层和官方公共层。
  • 当函数配置多个层时,这些层的内容将被合并至/opt目录,多个层按照层配置的逆序合并。如果多个层中有同名文件,先配置的层会覆盖后配置的层中的同名文件。

通过Serverless Devs配置官方公共层

前提条件

操作步骤

  1. 执行以下命令查找指定地域下的自定义层。
    s cli fc layer list --official --region cn-hangzhou
    执行成功后,返回官方公共层列表,如下所示。从中获取目标层的新ARN(即arnV2)并记录。
    -
      layerName:         Aliyun-DataX
      arn:
      arnV2:             acs:fc:cn-hangzhou:official:layers/Aliyun-DataX/versions/1
      version:           1
      acl:               1
      description:       Aliyun DataX for python (datax_v202205)
      compatibleRuntime:
        - custom
        - python2.7
        - python3
        - python3.9
    -
      layerName:         Python36-SciPy1x
      arn:
      arnV2:             acs:fc:cn-hangzhou:official:layers/Python36-SciPy1x/versions/1
      version:           1
      acl:               1
      description:       SciPy Layer for python36(scipy-1.5.4,numpy-1.19.5)
      compatibleRuntime:
        - custom
        - python3
    示例解析如下:
    • layerName:层名称。
    • version:层版本。
    • arn:层的旧ARN。只支持在自定义层中使用。
    • arnV2:层的新ARN。支持在自定义层和官方公共层中使用。
    • acl:层的权限。取值0代表私有,取值1代表公有。官方公共层默认为公有,自定义层可以设置为私有或者公有。
    • description:层的描述信息。
    • compatibleRuntime:兼容的运行时列表。
  2. 在任意目录下创建s.yaml文件,填写获取的层的新ARN。
    示例如下:
    edition: 1.0.0          #  命令行YAML规范版本,遵循语义化版本(Semantic Versioning)规范
    name: fcDeployApp       #  项目名称
    access: "default"  #  密钥别名
    
    services:
      fc-deploy-test: #  服务名称
        component: fc  # 组件名称
        props: #  组件的属性值
          region: cn-hangzhou
          service:
            name: fctest
            description: 'test'
            internetAccess: true
          function:
            name: emoji #  函数名称
            description: this is a layer demo
            runtime: python3.9
            codeUri: ./
            handler: index.handler
            memorySize: 128
            timeout: 6
            layers:    # 函数绑定层,取值是层的ARN
              - acs:fc:cn-hangzhou:official:layers/Aliyun-DataX/versions/1
              - acs:fc:cn-hangzhou:official:layers/Python39-SciPy1x/versions/1
  3. s.yaml文件所在目录,执行以下命令部署函数并为其配置层。
    s deploy

更多信息

您还可以通过API或SDK来管理层和配置层。您可以在以下API中配置层:

您可以通过OpenAPI Explorer调用API和SDK。