This document describes how to quickly create, configure, and deploy a web framework application in Tencent Cloud through Serverless Framework.
npm install -g serverless
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.
In an empty folder directory, run the following command:
Next, follow the interactive prompts to initialize the project. Please select the application framework template you want to deploy (Express is used as an example here):
Serverless: No serverless project is detected. Do you want to create one? Yes Serverless: Please select the serverless application you want to create: express-starter eggjs-starter - quickly deploys a basic Egg.js application ❯ express-starter - quickly deploys a basic Express.js application flask-starter - quickly deploys a basic Flask application fullstack - quickly deploys a full stack application (Vue.js + Express + Postgres) koa-starter - quickly deploys a basic Koa.js application laravel-starter - quickly deploys a basic Laravel application nextjs-starter - quickly deploys a basic Next.js application Serverless: Please enter the project name: demo Serverless: Installing the express-starter application... express-starter › Created The demo project has been successfully created!
Select Deploy Now to quickly deploy the initialized project to the Tencent Cloud platform:
Serverless: Do you want to deploy the project in the cloud now? Yes xxxxxxxx x QR x x CODE x xxxxxxxx Please scan the QR code above with WeChat or click the link below to log in https://slslogin.qcloud.com/XKYUcbaK Logged in successfully! serverless ⚡framework Action: "deploy" - Stage: "dev" - App: "demo1" - Instance: "expressDemo" region: ap-guangzhou apigw: serviceId: service-xxxxx subDomain: service-xxxxx.gz.apigw.tencentcs.com environment: release url: https://service-xxxxx.gz.apigw.tencentcs.com/release/ scf: functionName: express_component runtime: Nodejs10.15 namespace: default lastVersion: $LATEST traffic: 1 26s › expressDemo › Success
After the deployment is completed, click the API Gateway link output by the command line to quickly access the successfully deployed web framework application.
If you want to check the deployment status and resources of the application again, you can go to the folder where the project is successfully deployed and run the following command to view the corresponding information:
cd demo # Enter the project directory. Please change to your actual project's directory name here sls info
slsis short for the
In the directory of the initialized project, you can see the most basic structure of an Express project:
. ├── serverless.yml # Configuration file ├—— index.js # Entry function ├—— package.json # Project dependencies └── .env # Environment variable file
serverless.ymlconfiguration file implements the quick configuration of the basic function information. All the configuration items supported by the SCF console can be configured in the
.ymlfile (for more information, please see SCF Configuration Information).
index.jsis the entry function of the project, which is the
packageis the dependent file of the project, which records the dependency package that should be installed for the Express project.
.envfile stores user login authentication information. You can also configure other environment variables in it.
In the local project directory, you can modify the function template and configuration file, reinstall the dependencies, and then redeploy the project by running the following command:
If you want to view the details during the removal process, you can add the
After the deployment is completed, you can log in to the SSR console to view the monitoring metric data output after project deployment, such as the basic information, the number of project requests, and project error statistics.
View the monitoring metric data output after project deployment, such as the basic information, the number of project requests, and project error statistics, and implement the continuous development and deployment of the project.
For more information, please see Console Deployment Guide.
Serverless Framework supports running different commands to help you implement continuous development, deployment, and grayscale release for the project. You can also use this component in conjunction with other advanced capabilities such as layer and custom domain name to configure advanced features for the application.
Solution: add the
SERVERLESS_PLATFORM_VENDOR=tencent configuration item to the
sls deployis entered in a network environment outside the Chinese mainland, the deployment is very slow.
Solution: add the
GLOBAL_ACCELERATOR_NA=true configuration item to the
.env file to enable acceleration outside the Chinese mainland.
sls deployis entered, the deployment reports a network error.
Solution: add the following proxy configuration to the
HTTP_PROXY=http://127.0.0.1:12345 # Replace "12345" with your proxy port
HTTPS_PROXY=http://127.0.0.1:12345 # Replace "12345" with your proxy port