Overview
This document describes how to create, configure, and deploy a web framework application in Tencent Cloud through Serverless Framework.
Prerequisites
npm install -g serverless
Directions
Quick deployment
In an empty folder directory, run the following command:
Next, follow the prompts to initialize the project. 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 deploy the initialized project to Tencent Cloud:
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:
Note:
sls
is short for the serverless
command.
Viewing directory structure
In the directory of the initialized project, you can see the most basic structure of an Express project:
.
├── serverless.yml
├—— index.js
├—— package.json
└── .env
The serverless.yml
configuration file implements the quick configuration of the basic function information. All the configuration items supported by the SCF console can be configured in the .yml
file (for more information, please see SCF Configuration Information). index.js
is the entry function of the project, which is the helloworld
template here.
package
is the dependent file of the project, which records the dependency package that should be installed for the Express project.
The .env
file stores user login authentication information. You can also configure other environment variables in it.
Redeployment
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:
npm install && sls deploy
Note:
If you want to view the details during the removal process, you can add the --debug
parameter after sls deploy
.
Continuous development
After the deployment is completed, you can log in to the SLS 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, 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. FAQs
Problem 1: The wizard does not pop up by default when serverless
is entered.
Solution: Add the SERVERLESS_PLATFORM_VENDOR=tencent
configuration item to the .env
file.
Problem 2: After sls deploy
is 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.
Problem 3: Ater sls deploy
is entered, the deployment reports a network error.
Solution: Add the following proxy configuration to the .env
file.
HTTP_PROXY=http://127.0.0.1:12345
HTTPS_PROXY=http://127.0.0.1:12345
Was this page helpful?