PostgreSQL for Serverless (ServerlessDB) is a database product that allocates resources on demand based on PostgreSQL. Its database automatically allocates resources based on your actual number of requests. With PostgreSQL for Serverless, you can create a database instance for easy use without caring about the instance specifications. You only need to pay for the actual usage when the database is active.
Through the PostgreSQL for Serverless component, you can create, configure, and manage PostgreSQL instances with speed and ease.
Use npm to install Serverless CLI globally:
npm install -g serverless
.env file locally:
$ 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
Create a directory and enter it:
$ mkdir tencent-postgreSQL && cd tencent-postgreSQL
serverless.yml file in a new directory:
serverless.yml as follows:
# serverless.yml component: postgresql # Name of the imported component, which is required. The `postgresql` component is used in this example name: serverlessDB # Name of the instance created by this component, which is required org: test # Organization information, which is optional. The default value is the `appid` of your Tencent Cloud account app: serverlessDB # SQL application name, which is optional stage: dev # Information for identifying environment, which is optional. The default value is `dev` inputs: region: ap-guangzhou # Valid values: ap-guangzhou, ap-shanghai, ap-beijing zone: ap-guangzhou-2 # Valid values: ap-guangzhou-2, ap-shanghai-2, ap-beijing-3 dBInstanceName: serverlessDB vpcConfig: vpcId: vpc-xxxxxxx subnetId: subnet-xxxxxx extranetAccess: false
The PostgreSQL component supports "zero" configuration deployment, that is, it can be deployed directly through the default values in the configuration file. Nonetheless, you can also modify more optional configuration items to further customize your project.
Currently, PostgreSQL for Serverless is available for creation and deployment only in Beijing Zone 3, Guangzhou Zone 2, and Shanghai Zone 2. Therefore, when entering the region and AZ information in the
yamlfile, please be sure to use the correct region and corresponding VPC and subnet information.
Deploy by running the
sls command, and you can add the
--debug parameter to view the information during the deployment process:
slsis short for the
$ sls deploy
You can run the following commands to remove the deployed database instance:
$ sls remove
After deploying the PostgreSQL Serverless database, you can refer to Deploying Full-Stack Website with Vue + Express + PostgreSQL to use this database instance.
You can view more component information in the repository of Serverless Components.