Online Dependency Installation

Last updated: 2021-07-28 17:42:45

    Overview

    Tencent Cloud SCF supports online dependency installation during function deployment.

    Features

    Note:

    Currently, online dependency installation is supported only for Node.js.

    If "Online install dependency" is enabled in the function configuration, each time the code is uploaded, the SCF backend will check the package.json file in the root directory of the code package and try using npm install to install the dependencies based on the dependencies in package.json.

    For example, if the package.json file in the project lists the following dependency:

    {
        "dependencies": {
        "lodash": "4.17.15"
      }
    }
    

    Then this dependency will be imported into the function during the deployment:

    const _ = require('lodash');
    exports.handle = (event, context, callback) => {
      _.chunk(['a', 'b', 'c', 'd'], 2);
      // => [['a', 'b'], ['c', 'd']]
    };
    

    Directions

    You can implement the dependency installation feature of SCF in either of the following ways:

    1. Log in to the SCF console and select the Guangzhou region.
    2. Select Function Service on the left sidebar and select the function name on the Function Service list page.
    3. Select the Function code tab and modify the function code as needed.
    4. In the top-right corner of the IDE code editing window, click and select Automatic dependency installation: disable in the drop-down list to enable automatic dependency installation as shown below:
    5. Click Deploy, and the SCF backend will automatically install dependencies according to package.json.