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.
Features:
Use npm to install Serverless CLI globally:
$ npm install -g serverless
Create the .env
file locally:
$ touch .env # Tencent Cloud configuration information
Configure Tencent Cloud's SecretId
and SecretKey
information in the .env
file and save it:
# .env
TENCENT_SECRET_ID=123
TENCENT_SECRET_KEY=123
Note:
- If you don't have a Tencent Cloud account yet, please sign up first.
- If you already have a Tencent Cloud account, you can get
SecretId
andSecretKey
in API Key Management.
Create a directory and enter it:
$ mkdir tencent-postgreSQL && cd tencent-postgreSQL
Create a serverless.yml
file in a new directory:
$ touch serverless.yml
Configure 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.
Note:
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
yaml
file, 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:
Note:
sls
is short for theserverless
command.
$ 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.
Was this page helpful?