tencent cloud

Feedback

Layer Deployment

Last updated: 2024-12-02 10:48:10

    Overview

    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.

    Directions

    Creating layer

    You can create a layer and upload dependencies in the following two ways:
    Create in the SSR console
    Use the Layer component of Serverless Framework (for more information, please see Layer Component)

    Using layer

    You can use layer deployment in project configuration in the following two ways: console configuration and local configuration.

    Configuring in console

    For applications in the Node.js framework, Serverless Framework will automatically create a layer named ${appName}-layer and upload the application dependency node_modules to this layer.
    When importing an existing project, you can also choose to create a layer or use an existing layer for deployment. If you create a layer, Serverless Framework will automatically upload the application dependency 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.

    Configuring through Layer component

    1. 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
    2. 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.
    3. 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.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support