Deploying Egg.js Framework

Last updated: 2020-07-21 18:32:34

    Operation Scenarios

    Tencent Cloud Egg.js Serverless Component supports deploying RESTful API services.



    You are recommended to use Node.js 10.0 or above; otherwise, Component v2 may report errors during deployment.

    Initialize Egg.js project

    $ mkdir serverless-egg && cd serverless-egg
    $ npm init egg src --type=simple
    $ cd src && npm install

    Modify Egg.js configuration

    When a function is executed, only /tmp is readable/writable; therefore, you need to write the logs of Egg.js framework running attempts into this directory by modifying the configuration in config/config.default.js to the following:

    const config = (exports = {
      rundir: '/tmp',
      logger: {
        dir: '/tmp'


    1. Install

    Use npm to install Serverless CLI globally:

    $ npm install -g serverless

    2. Configure

    Create a serverless.yml file in the project root directory:

    $ touch serverless.yml

    Configure the serverless.yml file as follows:

    # serverless.yml
    org: orgDemo
    app: appDemo
    stage: dev
    component: egg@0.0.0-dev
    name: eggDemo
      src: ./src
      region: ap-guangzhou
      functionName: eggDemo
      runtime: Nodejs10.15
          - http
          - https
        environment: release

    Detailed Configuration >>

    3. Deploy

    Deploy by running the sls deploy command, and you can add the --debug parameter to view the information during the deployment process:


    sls is short for the serverless command.

    $ sls deploy
        region:              ap-beijing
        functionName:        egg-function
        apiGatewayServiceId: service-n5m5e8x3
      32s › MyComponent › done

    4. Remove

    You can run the following commands to remove the deployed API Gateway and SCF services:

    $ sls remove --debug
      DEBUG ─ Flushing template state and removing all components.
      DEBUG ─ Removing function
      DEBUG ─ Request id
      DEBUG ─ Removed function egg-function successful
      DEBUG ─ Removing any previously deployed API. api-cmkhknda
      DEBUG ─ Removing any previously deployed service. service-n5m5e8x3
      8s › MyComponent › done

    Account configuration (optional)

    Currently, you can scan a QR code to log in to the CLI by default. If you want to configure persistent environment variables/key information, you can also create a local .env file:

    $ touch .env # Tencent Cloud configuration information

    Configure Tencent Cloud's SecretId and SecretKey information in the .env file and save it:

    # .env


    • If you don't have a Tencent Cloud account yet, please sign up first.
    • If you already have a Tencent Cloud account, you can get SecretId and SecretKey in API Key Management.

    More Resources


    1. What should I do if the app/public deployment directory does not exist?

      Generally, when you initialize an Egg.js project, the app/public directory will be created automatically. If this directory is empty during packaging and compressing, it will not exist after the deployment; instead, it will automatically be created when the Egg.js project is started; however, SCF will not have the permission to manipulate it. Therefore, you are recommended to create an empty folder .gitkeep in the app/public directory to solve this problem.

    2. What should I do if a failure to find the dependent module is reported after deployment with Layer?

      For more information, please see here.

    More components

    You can view more component information in the repository of Serverless Components.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback