The SLS framework deployment scheme has been upgraded. You can use an SCF HTTP-triggered function to quickly deploy your Nest.js service to the cloud.
Note:What are the differences between SLS console deployment and direct function deployment?
Both SLS console deployment and function deployment can be based on HTTP-triggered functions, and quick deployment is usually used for web frameworks.
Before using Tencent Cloud SCF, you need to sign up for a Tencent Cloud account and complete identity verification.
Note:This document introduces the SLS console deployment scheme. You can also complete the deployment in CLI by referring to Deploying Web Function on Command Line.
The Node.js runtime environment has been installed locally.
Refer to First steps to initialize your Nest.js project:
npm i -g @nestjs/cli
nest new nest-app
In the root directory, run the following command to directly start the service locally.
cd nest-app && npm run start
Visit http://localhost:3000
in a browser, and you can access the sample Nest.js project locally.
You need to make simple modifications to the initialized project, so that the project can be quickly deployed through an HTTP-triggered function. The project transformation here is usually divided into the following two steps:
scf_bootstrap
file.0.0.0.0:9000
.The detailed steps are as follows:
Change the listening port to 9000
in the ./dist/main.js
file.
Create the scf_bootstrap
file in the root directory of the project and add the following content to it (the file is used to start the service):
Note:You can also complete the configuration in the console.
#!/bin/bash
SERVERLESS=1 /var/lang/node12/bin/node ./dist/main.js
Note:
After the file is created, you need to run the following command to modify the executable permission of the file. By default, the permission 777
or 755
is required for the service to start normally. Below is the sample code:
chmod 777 scf_bootstrap
You can configure the scf_bootstrap
file in the console. When the configuration is completed, the console automatically generates the scf_bootstrap
file and packages it and the project code for deployment.
Note:The actual
scf_bootstrap
file in your project prevails. If thescf_bootstrap
file already exists in your project, its content will not be overwritten.
When the configuration is completed, click Complete to deploy your Nest.js project.
Was this page helpful?