All Products
Search
Document Center

Function Compute (2.0):Configure common layers for a function

Last Updated:Jun 26, 2023

Function Compute provides common layers. You can configure the layer feature for your functions without providing custom layers. This topic describes how to configure common layers for a function.

Common layers supported by Function Compute

Function Compute supports the following types of common layers. This section lists some common layers. For more information about all the common layers supported by Function Compute, see Common layers.

If you fail to find the layer that you want to use, Contact Us.

Custom Runtime

Custom runtimes, such as Python 3.10 and Node.js 17, are included. In addition, collections of the dependency libraries for some custom runtimes are provided. For example, the common layer Python310-Package-Collection contains some dependency libraries commonly used in Python.

Common layerCompatible runtimeDescriptionUsage notes
Python310
  • Custom
  • Custom.Debian10
Python 3.10.5 runtime layerREADME.md
Python310-Package-Collection
  • Custom
  • Custom.Debian10
A collection of common dependency libraries for the Python 3.10 runtimeREADME.md
Python39
  • Custom
  • Custom.Debian10
Python 3.9.13 runtime layerREADME.md
Python39-Package-Collection
  • Custom
  • Custom.Debian10
A collection of common dependency libraries for the Python 3.9 runtimeREADME.md
Python38
  • Custom
  • Custom.Debian10
Python 3.8.13 runtime layerREADME.md
Python38-Package-Collection
  • Custom
  • Custom.Debian10
A collection of common dependency libraries for the Python 3.8.13 runtimeREADME.md
Python36CustomPython 3.6.15 runtime layerREADME.md
Python36-Package-CollectionCustomA collection of common dependency libraries for the Python 3.6.15 runtimeREADME.md
Dotnet6CustomASP.NET 6.0.5 runtime layerREADME.md
PHP81CustomPHP 8.1 runtime layerREADME.md
PHP80CustomPHP 8.0 runtime layerREADME.md
PHP72CustomPHP 7.2 runtime layerREADME.md
Java8Custom.Debian10Java 8 runtime layerREADME.md
Java11CustomJava 11 runtime layerREADME.md
Java17CustomJava 17 runtime layerREADME.md
Nodejs18Custom.Debian10Node.js 18 runtime layerREADME.md
Nodejs17CustomNode.js 17 runtime layerREADME.md
Nodejs16
  • Custom
  • Custom.Debian10
Node.js 16 runtime layerREADME.md
Nodejs14CustomNode.js 14 runtime layerREADME.md
Nodejs12CustomNode.js 12 runtime layerREADME.md
Go118CustomGo 1.x runtime layerREADME.md

Common dependency libraries

Common layerCompatible runtimeDescriptionVersion (the version number of the core library)Usage notes
Python39-Pandas1x
  • Python 3.9
  • Custom
  • Custom.Debian10
An open source data analysis and processing tool based on NumPy
  • pandas==1.4.3
  • numpy==1.23.2
README.md
Python39-SciPy1x
  • Python 3.9
  • Custom
An open source scientific computing library
  • scipy==1.9.0
  • numpy==1.23.2
README.md
Python36-SciPy1x
  • Python 3.6
  • Custom
An open source scientific computing library
  • scipy-1.5.4
  • numpy-1.19.5
README.md
Python39-PyTorch1x
  • Python 3.9
  • Custom
  • Custom.Debian10
An open source machine learning framework (CPU edition)
  • torch==1.12.1+cpu
  • torchaudio==0.12.1+cpu
  • torchvision==0.13.1+cpu
README.md
Python36-PyTorch1x
  • Python 3.6
  • Custom
An open source machine learning framework (CPU edition)
  • 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
A Python-based lightweight web frameworkv2.2.2README.md
Nodejs-Puppeteer17x
  • Node.js 16
  • Node.js 14
  • Custom
  • Custom.Debian10
A Headless Chrome toolpuppeteer-v17.1.0README.md
Nodejs-Puppeteer10x
  • Node.js 16
  • Node.js 14
  • Node.js 12
  • Custom
A Headless Chrome toolpuppeteer-v10.2.0README.md
Python310-Opencv4x
  • Python 3.10
  • Custom.Debian10
A cross-platform library for computer vision.v4.7.0.68README.md
SQLite3
  • Python 3.9
  • Node.js 16
  • Node.js 14
  • Java 11
  • Java 8
  • Custom
A lightweight and in-process relational database3.41.1README.md
FFmpeg6x
  • Python 3.10
  • Python 3.9
  • Node.js 16
  • Node.js 14
  • Java 11
  • Java 8
  • Custom
  • Custom.Debian10
An open source software project that consists of a large suite of programs used to record audio and videos, convert audio and video formats, and stream audio and video files.6.0README.md
Nodejs-Puppeteer19xCustom.Debian10A Headless Chrome toolpuppeteer-v19.8.5README.md
Python38-PlaywrightCustom.Debian10puppeteer-v19.8.51.31.1README.md
Poppler22x-Pdf2imagePython 3.10A library for rendering PDF documents22.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
An open source serverless platform that provides a robust set of tools for developers2.1.14README.md

Web framework

Common layerCompatible runtimeVersion (the version number of the core library)Usage notes
Python3-Flask2x
  • Python 3.9
  • Custom
flask-2.2.2README.md

Alibaba Cloud SDKs

Common layerCompatible runtimeDescriptionUsage notes
Aliyun-DataX
  • Python 2.7
  • Python 3
  • Python 3.6
  • Python 3.9
  • Custom
  • Custom.Debian10
Open source edition of Alibaba Cloud DataWorks Data IntegrationREADME.md
Python39-Aliyun-SDK
  • Python 3.9
  • Custom
Common Alibaba Cloud SDKs for Python 3.9README.md
Python36-Aliyun-SDK
  • Python 3.6
  • Custom
Common Alibaba Cloud SDKs for Python 3.6README.md
Nodejs-Aliyun-SDK
  • Node.js 16
  • Node.js 14
  • Node.js 12
  • Custom
  • Custom.Debian10
Common Alibaba Cloud SDKs for Node.js16, Node.js 14, and Node.js 12README.md

Configure common layers by using the console

Prerequisites

Create a function

Procedure

  1. Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.
  2. In the top navigation bar, select a region. On the Services page, click the desired service.
  3. On the Functions page, find the desired function and click Configure in the Actions column.
  4. In the Layers section, click + Add Layer and select Add Official Common Layer from the drop-down list.
  5. In the Official Common Layer drop-down list, view the layer description and license information and select a common layer. Select a layer version from the Layer Version drop-down list, and then click Save.
Note
  • A function can be configured with a maximum of five layers, including custom layers and public layers.
  • When multiple layers are configured for a function, the content of these layers is merged and stored in the /opt directory in reverse order. If layers contain files with the same name, the files in the first configured layer overwrites the files with the same names in the later configured layer.

Configure common layers by using Serverless Devs

Prerequisites

Procedure

  1. Run the following command to find the custom layers in the specified region:
    s cli fc layer list --official --region cn-hangzhou
    After the execution is successful, return to the list of common layers. Obtain and record the new ARN (arnV2) of the desired layer.
    -
      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
    The following content describes the code snippets in the sample code:
    • layerName: the name of the layer.
    • version: the version of the layer.
    • arn: the original ARN of the layer. The original ARN can be used only in custom layers.
    • arnV2: the new ARN of the layer. The new ARN can be used only in public layers.
    • acl: the permissions of the layer. The digit 0 specifies that the layer is private and the digit 1 specifies that the layer is public. By default, the public layers are public. The custom layers can be set to private or public.
    • description: the description of the layer.
    • compatibleRuntime: the list of compatible runtimes.
  2. Create the s.yaml file in any directory and enter the new ARN of the layer.
    Example:
    edition: 1.0.0          #  The version of the YAML syntax. The version complies with the semantic versioning specification.
    name: fcDeployApp       #  The name of the project.
    access: "default"  #  The alias of the key.
    
    services:
      fc-deploy-test: #  The name of the service.
        component: fc  # The name of the component.
        props: # The property value of the component.
          region: cn-hangzhou
          service:
            name: fctest
            description: 'test'
            internetAccess: true
          function:
            name: emoji # The name of the function.
            description: this is a layer demo
            runtime: python3.9
            codeUri: ./
            handler: index.handler
            memorySize: 128
            timeout: 6
            layers:    # The layers bound to the function. The values are the ARNs of the layers.
              - acs:fc:cn-hangzhou:official:layers/Aliyun-DataX/versions/1
              - acs:fc:cn-hangzhou:official:layers/Python39-SciPy1x/versions/1
  3. Run the following command in the directory in which the s.yaml file is stored to deploy the function and configure the layers for the function:
    s deploy

Additional information

You can also use API operations or SDKs to manage and configure layers. You can configure layers by calling the following API operations:

You can use OpenAPI Explorer to call API operations and use SDKs.