Help Center/ FunctionGraph/ User Guide/ Configuring Functions/ Configuring Dependencies/ Creating a Private Dependency for a Function
Updated on 2025-08-19 GMT+08:00

Creating a Private Dependency for a Function

This section describes how to create a private dependency of a function on your local PC.

Notes and Constraints

  • The maximum size of a dependency is 300 MB, and the maximum number of files in a dependency is 30,000.
  • The name of a file in a dependency cannot end with a tilde (~), for example, module~.
  • If the modules to be installed need dependencies such as .dll, .so, and .a, archive them to a .zip package.
  • You are advised to create function dependencies in Huawei Cloud EulerOS 2.0. If other OSs are used, the dynamic link library may not be found due to the differences between underlying dependency libraries.

Setting Up the EulerOS Environment

You are advised to create function dependencies in EulerOS. EulerOS is an enterprise-grade Linux OS based on open-source technology. It features high security, scalability, and performance, meeting customers' requirements for IT infrastructure and cloud computing services.

You can set up the Huawei Cloud EulerOS environment using the following methods:

  • Buy a EulerOS ECS on Huawei Cloud by referring to Purchasing and Logging In to a Linux ECS. On the Configure Basic Settings page, select Public Image, and select Huawei Cloud EulerOS and an image version.
  • Download the EulerOS image, and use virtualization software to set up the EulerOS VM on a local PC.

Creating a Function Dependency

The following describes how to create dependencies for different runtime functions.

Before creating a dependency, ensure that Node.js matching the function runtime has been installed in the environment. The following uses Node.js 8.10 as an example to describe how to create a MySQL dependency.

Do not run the CNPM command to generate Node.js dependencies.

  1. Run the following command to install the MySQL dependency.

    npm install mysql --save

    The node_modules folder is generated under the current directory.

  2. Run the following command to package the node_modules folder into a ZIP package, that is, the dependency.

    zip -rq mysql-node8.10.zip node_modules

To package multiple dependencies, follow the steps below:

  1. Create a package.json file with the following content:

    {
    	"name": "test",                     //Customized dependency name
    	"version": "1.0.0",                 //Dependency version
    	"dependencies": {
    		"redis": "~2.8.0",          
    		"mysql": "~2.17.1"
    	}
    }

  2. Run the following command in the directory where the package.json file is stored:

    npm install --save

  3. Compress node_modules into a ZIP package. This generates a dependency that contains both MySQL and Redis.

    zip -rq node8.10.zip node_modules

Before creating a dependency, ensure that Python matching the function runtime has been installed in the environment.

The following uses Python 3.12 as an example to describe how to create a PyMySQL dependency.

  1. Run the following command to install the PyMySQL dependency to the local /tmp/pymysql directory.

    pip install PyMySQL --root /tmp/pymysql

  2. Run the following command to access the specified directory.

    cd /tmp/pymysql/

  3. Go to the site-packages directory (generally lib/python3.12/site-packages/). If no dependency file exists in this directory, run the find command to find the file and go to its directory. Then run the following command to compress the dependency file.

    The required dependency is generated.

    zip -rq pymysql.zip *

To install the local wheel installation package, run the following commands:

pip install piexif-1.1.0b0-py2.py3-none-any.whl --root /tmp/piexif   
//Replace piexif-1.1.0b0-py2.py3-none-any.whl with the actual installation package name.

Before creating a dependency, ensure that PHP matching the function runtime has been installed in the environment. The following uses PHP 7.3 as an example to describe how to install the protobuf3.19 dependency using Composer. Composer has been installed in the default environment. The procedure is the same for other PHP versions.

  1. Create the composer.json file with the following content:

    {
        "require": {
            "google/protobuf": "^3.19"
        }
    }

  2. Run the following command:

    Composer install

    The vendor folder is generated with the autoload.php, composer, and google subfolders in the current directory.

  3. Run the following command to generate a ZIP package:

    zip –rq vendor.zip vendor

If multiple dependencies need to be packaged, specify them in the composer.json file, compress the vendor folder into a ZIP file and upload it.

In PHP projects, third-party dependencies downloaded using Composer need to be loaded using require "./vendor/autoload.php". By default, FunctionGraph stores the decompressed files in a directory at the same level as the project code directory.

When you compile a function using Java, dependencies need to be compiled locally. For details about how to create a dependency, see Developing Functions in Java (Using an IDEA Java Project).

When you compile a function using Go, dependencies need to be compiled locally.

When you compile a function using C#, dependencies need to be compiled locally.

Helpful Links