This document introduces how to use a template to quickly deploy a full-stack serverless application based on Vue, Express, and PostgreSQL. The template mainly contains the following components:
Use npm to install Serverless Framework globally:
npm install -g serverless
If you have already installed Serverless Framework, you can run the following command to upgrade it to the latest version:
npm update -g serverless
After the installation is completed, run the serverless -v
command to view the version information of Serverless Framework. Versions earlier than those listed below are not allowed.
$ serverless –v
Framework Core: 1.74.1 (standalone)
Plugin: 3.6.14
SDK: 2.3.1
Components: 2.31.6
serverless init
command to download the related template.serverless init fullstack
In the root directory of the project, create an .env file and configure the corresponding Tencent Cloud SecretId, SecretKey, region, and availability zone (AZ) information in the file.
# .env
TENCENT_SECRET_ID=xxx // `SecretId` of your account
TENCENT_SECRET_KEY=xxx // `SecretKey` of your account
# Region and AZ configuration
REGION=ap-guangzhou // Resource deployment region, that is, the region for deploying SCF and static pages in this project
ZONE=ap-guangzhou-2 // Resource deployment AZ, that is, the AZ for deploying DBs in this project
Note:
- If you don't have a Tencent Cloud account yet, please sign up first.
- If you already have a Tencent Cloud account, ensure that your account is authorized with the "AdministratorAccess" permission. You can get
SecretId
andSecretKey
in API Key Management.ZONE
currently can only beap-beijing-3
,ap-guangzhou-2
, orap-shanghai-2
.
Run the following command to install required dependencies:
npm run bootstrap
Run the sls deploy --all
command to start deployment. The returned information is as follows:
$ sls deploy --all
serverless ⚡ framework
serverlessVpc:
region: ap-guangzhou
zone: ap-guangzhou-2
vpcId: vpc-xxx
vpcName: serverless
subnetId: subnet-xxx
subnetName: serverless
fullstackDB:
region: ap-guangzhou
zone: ap-guangzhou-2
vpcConfig:
subnetId: subnet-100000
vpcId: vpc-1000000
dBInstanceName: fullstackDB
dBInstanceId: postgres-100000
private:
connectionString: postgresql://tencentdb_100000xxxxxxxxxxxxx@172.16.250.15:5432/tencentdb_1000000
host: 172.16.250.15
port: 5432
user: tencentdb_100000
password: xxxxxxxx
dbname: tencentdb_100000
fullstack-api:
region: ap-guangzhou
apigw:
serviceId: service-100000
subDomain: service-100000-123456789.gz.apigw.tencentcs.com
environment: release
url: https://service-100000-123456789.gz.apigw.tencentcs.com/release/
scf:
functionName: fullstack-api
runtime: Nodejs10.15
namespace: default
fullstack-frontend:
website: https://fullstack-serverless-db-123456789.cos-website.ap-guangzhou.myqcloud.com
50s › tencent-fullstack › Success
After successful deployment, you can use a browser to access the website link generated by the project and see the generated website.
Note:In this project, SCF is in a VPC and therefore cannot directly access a public network. To enable it to access a public network, configure the SCF network.
You can run sls remove --all
to remove the project. The returned information is as follows:
$ sls remove --all
serverless ⚡ framework
38s › tencent-fullstack › Success
Was this page helpful?