This document describes how to create, bind, and use a layer in the SCF Console.
This section uses Node.js as an example to describe how to create a layer, bind it to a locally uploaded function, and use it.
node_modules to generate a layer as instructed in Creating layer.
Package and upload the local function code as instructed in Deploying Function. During the packaging, run the following command to exclude the
zip -r package name.zip . -x "node_modules/*"
Bind the created layer to the deployed function as instructed in Binding function to layer.
You can use the layer in the function after completing the steps above.
NODE_PATH environment variable contains the
/opt/node_modules path, you can find the dependency in the layer when running the function. You can use the dependency in the same way as before with no code modification required. This document uses the
cos-nodejs-sdk-v5 dependency as an example.
For the environment variables in Python, Java, and Node.js, please see the table below:
Go to scf_layer_demo and select Clone or download > Download ZIP to download the demo and decompress it.
Create a layer as instructed in Creating layer. Set the parameters.
demoas an example.
layerfolder in the folder obtained in step 1.
Go to the "Function Service" page and click Create to enter the "Create Function" page.
Set the basic information of the function in "Basic Info" on the "Create Function" page and click Next.
layerDemoas an example.
In "Function Configuration", select "Local folder" as "Submission Method" and select and upload the
function folder in the folder obtained in step 1.
Click Advanced Settings and add the function layer in "Layer Configuration".
democreated in step 2.
Click Complete at the bottom to complete the function creation.
Select the Function Code tab on the "Function Management" page. You can click Test at the bottom to view the result.