Tencent Cloud Express component uses Tencent Serverless Framework. Based on serverless services (gateways, functions, etc.) in the cloud, it can implement "zero" configuration, convenient development, and rapid deployment of your Express application. The Express component supports a rich set of configuration extensions and provides the easiest-to-use, low-cost, and elastically scalable cloud-based Express project development and hosting capabilities.
Through the Serverless Framework Express component, you can quickly migrate traditional local Express applications to the serverless function platform.
If your account is a Tencent Cloud sub-account, please get the authorization from the root account first as instructed in Account and Permission Configuration.
The Express component will use the following Serverless services in your Tencent Cloud account:
The following steps are mainly for deployment on the command line. For deployment in the console, please see Console Deployment Guide.
If you don't have a local Express project, you can quickly create an Express project template with the following command (if you already have one, you can ignore this step):
serverless init express-starter --name example cd example
Open the entry file
app.js) of the Express project, comment out the local listening port, and export the default Express application:
// sls.js const express = require('express'); const app = express(); // ***** // Comment out the local listening port // app.listen(3000); // Export the Express application module.exports = app;
After modifying the code, you can run the
sls deploy command, and Serverless Framework will automatically generate a basic
serverless.yml file and complete the deployment to quickly migrate the Express framework application.
The generated default configuration file is as follows:
component: express name: expressDemo app: appDemo inputs: entryFile: sls.js # Use the actual entry file name src: ./ region: ap-guangzhou runtime: Nodejs10.15 apigatewayConf: protocols: - http - https environment: release
After the deployment is completed, access the application by accessing the output API Gateway link.
You can add more configuration items in
serverless.yml based on your actual deployment needs and run
sls deploy for redeployment.
For more information on the configuration of the .yml file, please see Express Component Configuration.
After the deployment is completed, you can log in to the Serverless Framework console to view the basic information of the application and monitor logs.
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
touch .env # Tencent Cloud configuration information
Configure Tencent Cloud's
SecretKey information in the
.env file and save it:
# .env TENCENT_SECRET_ID=123 TENCENT_SECRET_KEY=123