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.
If you only need to develop code logic and do not need to create additional resources, you can perform quick deployment through the SLS console.
If you need to create more capabilities or resources, such as automatic creation of layer hosting dependencies, quick implementation of static resource isolation, and support for direct code repository pulling, in addition to code deployment, you can use the SLS console to create web applications.
Template Deployment: Deploying Express Sample Code
2. Click Create Application and choose Web Application > Express Framework.
3. Click Next and complete the basic configuration. Select Sample Code as the upload mode.
4. Click Complete.
5. After the application is deployed, you can click the sample application name on the Application List page to go to the details page of the application.
6. On the Resource List page, click the access URL generated by the API gateway of the sample application to access the deployed Express project.
Custom Deployment - Quickly Deploying Web Application
The Node.js runtime environment has been installed locally.
1. After confirming that the Node.js runtime environment has been installed locally, install the Express framework and express-generator tool and initialize your sample Express project.
npm install express --save
npm install express-generator --save
2. Go to the project directory and install the dependency package.
3. After the installation is completed, you can directly start the service locally. Enter
http://localhost:3000 in a browser to access the sample Express project locally.
Deployment in cloud
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:
Change the listening address and port to
The detailed directions are as follows:
1. In the sample Express project, you can specify the listening address and port by using the environment variable in the
./bin/www file. If you don't specify it, port 3000 will be listened on by default.
2. Create the
scf_bootstrap file in the root directory of the project. This file is used to configure environment variables and specify service startup commands.
You can also complete the configuration in the console.
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.
3. After the local configuration is completed, run the bootstrap file and make sure that your service can be normally started locally. Then log in to the SLS console, choose Web Application > Express Framework, and select Local Upload or Code Repository Pull as the upload mode.
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_bootstrap file in your project prevails. If the
scf_bootstrap file already exists in your project, its content will not be overwritten.
When the configuration is completed, click Complete to deploy your Express project.