The SLS framework deployment scheme has been upgraded. You can use an SCF HTTP-triggered function to quickly deploy your Express service to the cloud.
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.
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.
npm install express --save npm install express-generator --save express WebApp
cd WebApp npm install
http://localhost:3000in a browser, and you can access the sample Express project locally.
Next, perform the following steps to make simple modifications to the initialized project, so that it can be quickly deployed through an HTTP-triggered function. The project transformation here is usually divided into the following two steps:
The detailed steps are as follows:
In the sample Express project, you can specify the listening address and port through the environment variable in the
./bin/www file. If you don't specify it, port 3000 will be listened on by default.
scf_bootstrap file in the root directory of the project. This file is used to configure environment variables and specify service start commands.
You can also complete the configuration in the console.
!/bin/bash export PORT=9000 npm run start
After the file is created, you need to run the following command to modify the executable permission of the file. By default, the permission
755 is required for the service to start normally.
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.
scf_bootstrapfile in your project prevails. If the
scf_bootstrapfile already exists in your project, its content will not be overwritten.
When the configuration is completed, click Complete to deploy your Express project.