tencent cloud

Serverless Cloud Function

Release Notes and Announcements
Release Notes
Announcements
User Guide
Product Introduction
Overview
Related Concepts
How It Works
Strengths
Scenarios
Related Products
Purchase Guide
Billing Overview
Billing Mode
Billable Items and Billing Modes
Function Computing Power Support
Free Tier
SCF Pricing
Billing Example
Payment Overdue
Getting Started
Creating Event Function in Console
User Guide
Quota Management
Managing Functions
Web Function Management
Log Management
Concurrence Management
Trigger Management
Function URL
A Custom Domain Name
Version Management
Alias Management
Permission Management
Running Instance Management
Plugin Management
Managing Monitors and Alarms
Network Configuration
Layer Management
Execution Configuration
Extended Storage Management
DNS Caching Configuration
Resource Managed Mode Management
Near-Offline Resource Hosting Model
Workflow
Triggers
Trigger Overview
Trigger Event Message Structure Summary
API Gateway Trigger
COS Trigger
CLS Trigger
Timer Trigger
CKafka Trigger
Apache Kafka Trigger
MQTT Trigger
Trigger Configuration Description
MPS Trigger
CLB Trigger Description
TencentCloud API Trigger
Development Guide
Basic Concepts
Testing a Function
Environment Variables
Dependency Installation
Using Container Image
Error Types and Retry Policies
Dead Letter Queue
Connecting SCF to Database
Automated Deployment
Cloud Function Status Code
Common Errors and Solutions
Developer Tools
Serverless Web IDE
Calling SDK Across Functions
Third-Party Tools
Code Development
Python
Node.js
Golang
PHP
Java
Custom Runtime
Deploying Image as Function
Web Framework Development
Deploying Framework on Command Line
Quickly Deploying Egg Framework
Quickly Deploying Express Framework
Quickly Deploying Flask Framework
Quickly Deploying Koa Framework
Quickly Deploying Laravel Framework
Quickly Deploying Nest.js Framework
Quickly Deploying Next.js Framework
Quickly Deploying Nuxt.js Framework
Quickly Deploying Django Framework
Use Cases
Overview
Solutions with Tencent Cloud Services
Business Development
TRTC Practices
COS Practices
CKafka Practice
CLS
CLB Practice
MPS
CDN
CDWPG
VOD
SMS
ES
Scheduled Task
Video Processing
Success Stories
Tencent Online Education
Online Video Industry
Tencent Online Education
Best Practice of Tencent IEG Going Global
API Documentation
History
Introduction
API Category
Making API Requests
Other APIs
Namespace APIs
Layer Management APIs
Async Event Management APIs
Trigger APIs
Function APIs
Function and Layer Status Description
Data Types
Error Codes
SDK Documentation
FAQs
General
Web Function
Billing FAQs
Network FAQs
Log FAQs
SCF utility class
Event Handling FAQs
API Gateway Trigger FAQs
Related Agreement
Service Level Agreement
Contact Us
Glossary

Quickly Deploying Egg Framework

PDF
Focus Mode
Font Size
Last updated: 2025-10-28 14:40:03

Overview

This document describes how to quickly deploy a local Egg project to the cloud through a web function.

Prerequisites

Before using SCF, you need to sign up for a Tencent Cloud account and complete identity verification first.

Directions

Template deployment - quick deployment of Egg project

1. Log in to the SCF console and click Function Service on the left sidebar.
2. Select the region where to create a function at the top of the page and click Create to enter the function creation process.
3. Select Template for Creation Method, enter Egg in the search box to filter function templates, select Egg Framework Template, and click Next as shown below:


4. On the Configuration page, you can view and modify the specific configuration information of the template project.
5. Click Complete. After creating the web function, you can view its basic information on the Function Management page.
6. You can access the deployed Egg project at the access path URL generated by API Gateway. Click Trigger Management on the left to view the access path as shown below:


7. Click the access path URL to access the Egg project.

Custom deployment - quick migration of local project to cloud

Prerequisites

The Node.js runtime environment has been installed locally.

Local development

1. Refer to Quick Start to quickly initialize the sample project as follows:
mkdir egg-example && cd egg-example
npm init egg --type=simple
npm i
2. In the root directory, run the following command to directly start the service locally.
npm run dev
open http://localhost:7001
3. Visit http://localhost:7001 in a browser, and you can access the sample Egg project locally.

Cloud deployment

Next, perform the following steps to make simple modifications to the initialized project, so that it can be quickly deployed through a web function. The project transformation here is usually divided into the following three steps:
Change the listening address and port to 0.0.0.0:9000.
Modify the write path. Only the /tmp directory is readable/writable in the SCF environment.
Add the scf_bootstrap bootstrap file.
The specific steps are as follows:
1. Create the scf_bootstrap bootstrap file in the project root directory and add the following content to it (which is used to configure environment variables and start services. Here is only a sample. Please adjust the specific operations according to your actual business scenario):
#!/var/lang/node12/bin/node

'use strict';

/**
* Node path in docker: /var/lang/node12/bin/node
* As only `/tmp` is readable/writable in SCF, two environment variables need to be modified at startup
* `NODE_LOG_DIR` changes the default node write path of `egg-scripts` (~/logs) to `/tmp`
* `EGG_APP_CONFIG` changes the default directory of the Egg application to `/tmp`
*/

process.env.EGG_SERVER_ENV = 'prod';
process.env.NODE_ENV = 'production';
process.env.NODE_LOG_DIR = '/tmp';
process.env.EGG_APP_CONFIG = '{"rundir":"/tmp","logger":{"dir":"/tmp"}}';

const { Application } = require('egg');

// If you deploy `node_modules` through layers, you need to modify `eggPath`
Object.defineProperty(Application.prototype, Symbol.for('egg#eggPath'), {
value: '/opt',
});

const app = new Application({
mode: 'single',
env: 'prod',
});

app.listen(9000, '0.0.0.0', () => {
console.log('Server start on http://0.0.0.0:9000');
});

2. After the creation is completed, you need to run the following command to modify the executable permission of the file. By default, the permission 777 or 755 is required for it to start normally. Below is the sample code:
chmod 777 scf_bootstrap

3. Log in to the SCF console and click Function Service on the left sidebar.
4. Select the region where to create a function at the top of the page and click Create to enter the function creation process.
5. Select Custom Creation for Creation Method and configure the options as prompted as shown below:


Function Type: select Web function.
Function Name: enter the name of your function.
Region: enter your function deployment region, which is Guangzhou by default.
Runtime Environment: select Nodejs 12.16.
Deployment Method: select Code deployment and upload your local project.
Submitting Method: select Local folder.
Function Code: select the specific local folder where the function code is.
6. Click Complete.

Development management

After the deployment is completed, you can quickly access and test your web service in the SCF console and try out various features of SCF, such as layer binding and log management. In this way, you can enjoy the advantages of low cost and flexible scaling brought by the serverless architecture.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback