Due to the limits of SCF, only code packages below 50 MB in size can be uploaded currently. If your project is too large, you can put dependencies in layers instead of the deployment package to reduce the package size. For specific usages of layers, please see Operations.
You can create a layer and upload dependencies in the following two ways:
You can use layer deployment in project configuration in the following two ways: console configuration and local configuration.
${appName}-layer
and upload the application dependency node_modules
to this layer.node_modules
to this layer.Note:
The layer creation operation is supported only for the Node.js framework. When using a layer in other frameworks, please make sure that the layer has already been created and the relevant dependencies have been uploaded to the layer.
The Next.js component is used as an example here. Adjust the local project directory, add a layer
folder, and create a serverless.yml file to configure the layer name and version. The .yml
template is as follows:
app: appDemo
stage: dev
component: layer
name: layerDemo
inputs:
name: test
region: ap-guangzhou
src: ../node_modules # Path of the file to be uploaded
runtimes:
- Nodejs10.14
For detailed configuration items, please see Layer Component Configuration.
The updated directory structure is as follows:
.
├── node_modules
├── src
│ ├── serverless.yml # Function configuration file
│ └── index.js # Entry function
├── layer
│ └── serverless.yml # Layer configuration file
└── .env # Environment variable file
Open the project configuration file, add the layer configuration item, and import the output of the Layer component as the input of the project configuration file. The template is as follows:
app: appDemo
stage: dev
component: nextjs
name: nextjsDemo
inputs:
src:
src: ./
exclude:
- .env
region: ap-guangzhou
runtime: Nodejs10.15
apigatewayConf:
protocols:
- http
- https
environment: release
layers:
- name: ${output:${stage}:${app}:layerDemo.name} # Layer name
version: ${output:${stage}:${app}:layerDemo.version} # Version
For the import format, please see Variable Import Description.
In the project root directory, run sls deploy
to complete layer creation and use the output of the Layer component as the input of the Next.js component to configure the layer.
Was this page helpful?