Skip to main content

Bootstrap File Description

In HTTP Cloud Functions, scf_bootstrap is a required startup file that serves as the entry point for the Web Server. It is responsible for starting your web service, configuring the runtime environment, loading dependencies, and ensuring the service properly listens for requests.

Purpose of the Bootstrap File

The scf_bootstrap file is automatically executed when a cloud function instance starts, primarily performing the following tasks:

ResponsibilityDescription
Start Web ServiceEnsures your web service starts properly and listens for requests (default port is 9000)
Environment ConfigurationSets paths for runtime dependency libraries, environment variables, etc.
Dependency LoadingLoads library files and extensions for custom languages and versions
For real-time dependency pulling, it's recommended to download to the /tmp directory
Global InitializationPerforms global operations required before function invocation
(such as HTTP Client initialization, database connection pool creation, etc.) for reuse during invocation
Plugin LoadingStarts security, monitoring, and other plugins

Prerequisites

To ensure the bootstrap file can be executed correctly, the following conditions must be met:

RequirementDescription
Fixed FilenameMust be named scf_bootstrap, other names are not supported
Execute PermissionFile must have execute permission (recommended 777 or 755)
System EnvironmentMust be able to run in SCF system environment (CentOS 7.6)
Shebang DeclarationIf it's a Shell script, the first line must include #!/bin/bash
Absolute PathStartup commands must use absolute paths (see "Standard Language Environment Absolute Paths" below)
Listen AddressIt's recommended to use 0.0.0.0, do not use internal loopback address 127.0.0.1
File FormatFile must end with LF line ending (not CRLF)
Write Permission RestrictionsIn Tencent Cloud standard environment, only the /tmp directory is readable/writable; please note the path when outputting files

⚠️ Important Note: On Linux/macOS systems, use the chmod +x scf_bootstrap or chmod 777 scf_bootstrap command to set execute permissions.

Standard Language Environment Absolute Paths

When writing startup commands, you must use the absolute path corresponding to the language. Here are common version path references:

Language VersionAbsolute Path
Node.js 18.15/var/lang/node18/bin/node
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
Python 3.10/var/lang/python310/bin/python3.10
Python 3.9/var/lang/python39/bin/python3.9
Python 3.7/var/lang/python37/bin/python3.7
Python 3.6/var/lang/python3/bin/python3.6
PHP 8.0/var/lang/php80/bin/php
PHP 7.4/var/lang/php74/bin/php
PHP 7.2/var/lang/php7/bin/php
Java 11/var/lang/java11/bin/java
Java 8/var/lang/java8/bin/java

Startup Command Templates

#!/bin/bash
node node_modules/@cloudbase/functions-framework/bin/tcb-ff.js --port=9000 --logDirname=/tmp/logs --interceptOutput=false --extendedContextKey=X-Cloudbase-Context

Parameter Description:

ParameterDescriptionDefault Value
--portFunction listening port9000
--logDirnameLog storage directory/tmp/logs
--interceptOutputWhether to intercept standard outputfalse
--extendedContextKeyExtended context request header keyX-Cloudbase-Context

💡 Tip: You need to install the @cloudbase/functions-framework dependency in package.json.

Express Framework

#!/bin/bash
export PORT=9000
/var/lang/node18/bin/node app.js

📝 Note: Please change app.js to your actual startup filename.

Next.js Framework

#!/bin/bash
export PORT=9000
/var/lang/node18/bin/node node_modules/next/dist/bin/next start