Within the standard language image environment built into the function, you need to create an executable file named scf_bootstrap to launch the Web Server. This file, along with your code files, should be packaged and deployed together to complete the creation of the HTTP-triggered Function. During actual request processing, your Web Server listens to the specified 9000 port to receive HTTP requests. These requests are then forwarded to the backend service for logical processing and response to the user.
Bootstrap File Usage
scf_bootstrap is the bootstrap file of your web server and ensures that your web service can normally start and listen on requests. In addition, you can customize scf_bootstrap to implement more personalized operations as needed:
Set the paths and environment variables of the runtime's dependency libraries.
Load the dependency library files and extensions of the custom programming language and version. If there are dependent files that need to be pulled in real time, you can download them to the /tmp directory.
Parse the function file and execute the global operations or initialization processes (such as initializing SDK client (HTTP client) and creating database connection pool) required before function invocation, so they can be reused during invocation.
Start plugins such as security and monitoring.
Note
SCF only supports reading scf_bootstrap as the bootstrap file name, and other names cannot start the service normally.
In the Tencent Cloud standard environment, only the /tmp directory is readable and writable. When outputting files, please select the /tmp path; otherwise, the service will exit exceptionally due to the lack of write permission.
Prerequisites
The permission to execute is required. Make sure that your scf_bootstrap file has the 777 or 755 permission; otherwise, it cannot be executed due to insufficient permissions.
Be able to run in the SCF system environment (CentOS 7.6).
If the bootstrap file is a shell script, it must have #!/bin/bash in the first line.
The bootstrap command must be the absolute path /var/lang/${specific_lang}${version}/bin/${specific_lang}; otherwise, it cannot be invoked normally. For more information, see Absolute Paths in Standard Language Environments.
The recommended listening address is 0.0.0.0, and the internal loopback address 127.0.0.1 cannot be used.
The file must end with an LF carriage return.
Creation method
Local package upload
Quick creation in console
You can write your scf_bootstrap file locally, make sure that the file permission meets the requirements, package it with the project code, and deploy them together on the HTTP-triggered function.
You can create an HTTP-triggered function in the Serverless Console. During the Create Function process, you can edit your bootstrap file under Advanced Configuration > Startup Command. SCF provides common startup templates for popular web frameworks, which you can modify according to your needs. As shown in the figure below:
Once the function is created, the console will automatically package and deploy your code along with the scf_bootstrap file.
Note
The configuration in the console takes effect only if no scf_bootstrap is detected in the uploaded code. If there is an scf_bootstrap file in your project, the system will deploy the function based on it.
Upon successful deployment, you can view and edit the scf_bootstrap file in the code editor, as shown in the figure below:
Troubleshooting common errors
The scf_bootstrap executable file serves as the container's startup command. It is crucial to ensure that the container can start and execute the code logic properly. Therefore, please make sure your startup command is written correctly. If you encounter an error code 405, it is usually due to the executable file not running correctly. Please ensure that your bootstrap file is written correctly.
Absolute Paths in Standard Languages Environments
Language Version
Absolute Path
Node.js 16.13
/var/lang/node16/bin/node
Node.js 14.18
/var/lang/node14/bin/node
Node.js 12.16
/var/lang/node12/bin/node
Node.js 10.15
/var/lang/node10/bin/node
Python 3.7
/var/lang/python37/bin/python3
Python 3.6
/var/lang/python3/bin/python3
Python 2.7
/var/lang/python2/bin/python
PHP 8.0
/var/lang/php80/bin/php
PHP 7.4
/var/lang/php74/bin/php
PHP 7.2
/var/lang/php7/bin/php
PHP 5.6
/var/lang/php5/bin/php
JAVA 11
/var/lang/java11/bin/java
JAVA 8
/var/lang/java8/bin/java
Common Web Server Bootstrap Command Templates
Nodejs
Python
PHP
#!/bin/bash
exportPORT=9000
/var/lang/node12/bin/node app.js # Change to your own bootstrap function name
#!/bin/bash
exportPORT=9000
/var/lang/python3/bin/python3 app.py # Change to your own bootstrap file name
#!/bin/bash
/var/lang/php7/bin/php -c /var/runtime/php7 -S 0.0.0.0:9000 hello.php # Change to your own entry function name