All Products
Search
Document Center

Function Compute:Install third-party dependencies for a function

Last Updated:Mar 21, 2025

Function Compute provides built-in runtimes that include common dependencies for your functions to reference. However, if these built-in dependencies cannot meet your business requirements, you can install additional third-party dependencies. This topic describes how to install third-party dependencies for a function.

Background

For more information about built-in common dependencies in Function Compute, see the following topics:

Install dependencies by using layers

The official public layers of Function Compute are pre-installed with common dependency libraries and can be directly used. You can also build a custom layer to install required dependencies. If you want to get more public layers, see awesome-layers.

Use public layers to install dependencies

  • Official public layers

    Log on to the Function Compute console, create a function or find the function that you want to manage, choose Configurations > Layers, and click Modify. In the Layers panel, choose + Add Layer > Add Public Layer. For more information, see Configure a public layer.

  • Non-official public layers

    Find the layer you want to use from awesome-layers and obtain the Alibaba Cloud Resource Name (ARN) of the layer. On the Function Details page, choose Configurations > Layers and click Modify. In the Layers panel, choose + Add Layer > Add Layer by ARN.

image

Use custom layers to install dependencies

  • Build a layer in the Function Compute console

    Log on to the Function Compute console. In the left-side navigation pane, choose Advanced Features > Layers. For more information, see Create a custom layer.

    Note

    This method does not support dependencies that contain system dynamic-link libraries with the .so extension, such as the Puppeteer dependency library for Node.js. If you want to install a dependency that contains a dynamic-link library (.so), we recommend that you use a Dockerfile to build the layer.

  • Build a layer on an on-premises machine

    You can build a custom layer on an on-premises machine, but it's essential to ensure that the on-premises operating system (OS) and processor architecture are completely consistent with the Function Compute runtime. This means you must use an x86-64 Linux OS or make sure that the installed dependency library does not depend on the underlying environment or processor architecture. For more information about how to build a custom layer, see Build a .ZIP file for a layer.

    Some dependencies, such as the Python numpy library, are environment-dependent. For example, if your on-premises machine runs macOS with M1 chips, you cannot install such dependencies on that machine.

  • Use a Dockerfile to build a layer

    If a dependency contains underlying dynamic-link libraries or fails to be installed on your on-premises machine, you can use a Dockerfile to build a layer and install the dependency. For more information, see Use a Dockerfile to build a layer.

Install dependencies in the Function Compute console

Package dependencies and upload them to the Function Compute console

  1. Compress third-party dependencies with your code into a package.

    Important
    • You must package all files in the code directory. Make sure the function handler file is in the root directory of the package.

    • The packaging method differs depending on the OS. Select a method that best fits your business requirements.

  2. Log on to the Function Compute console and upload a code package by using one of the following methods to deploy the function: Upload ZIP, Upload Folder, or OSS.

Install dependencies by using WebIDE in the Function Compute console

  1. Log on to the Function Compute console and find the function that you want to manage.

  2. On the Function Details page, click the Code tab. On the WebIDE UI, click Terminal > New Terminal. In Terminal, run the pip install -t . <PackageName> command to install dependencies.

    pip install -t . <PackageName>   # PackageName indicates the name of the dependency package. -t indicates the installation path. . indicates to install in the current directory.

    image

Use Serverless Devs to install dependencies

You can also create and deploy a function to Function Compute by using Serverless Devs. For more information, see Common commands of Serverless Devs.