Tencent Cloud SCF supports online dependency installation during function deployment.
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 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']]
};
You can implement the dependency installation feature of SCF in either of the following ways:
Note:
Every time the code is uploaded, the SCF backend will automatically install the dependencies.
5. Click Complete.
Note:
Every time the code is updated, the SCF backend will automatically install the dependencies.
5. Click Save.
Note:
You need to install the dependencies locally and upload the code package to the SCF platform in "Upload All" mode.
You can use the SCF CLI to directly run the relevant command to install the dependencies in the function folder; for example, run the following command to add the lodash
dependency:
npm install lodash
Was this page helpful?