This topic describes how to use a custom runtime to write functions in a Function Compute.
Background
You can use a custom runtime to create a dedicated runtime environment. A custom runtime allows you to:
- Use a specified programming language, such as Rust.
- Customize a runtime environment of a specified version for a programming language, such as Node.js 16.
Container environment
A custom runtime runs in the following container environment:
- Operating system: Debian 9
- Architecture: x86_64
- User permissions:
- If functions are created at and after 00:00:00 December 1, 2021, the functions must be executed by the root user.
- If functions are created before 00:00:00 December 1, 2021, the functions must be executed by a non-root user.
- Directory permissions:
- If functions are created at and after 00:00:00 December 1, 2021, all the directories are writable.
- For the functions that are created before 00:00:00 December 1, 2021, data can be written to only the /tmp directory.
- The directory of the code in the container: /code.
Information about the runtime environment
A custom runtime supports the following built-in languages. You can create custom runtimes of the following languages without the need to install third-party interpreters:
- Python 3.7.4
- Node.js 10.16.2
- OpenJDK 1.8.0
- Ruby 2.7
- PowerShell 7.1.0
- Nginx 1.10.3
- PHP 7.4.12Expand to see a list of PHP 7.4.12 built-in extensions.
bcmath calendar Core ctype curl date dom exif FFI fileinfo filter ftp gd gettext hash iconv imagick imap intl json libxml mbstring mcrypt memcached mysqli mysqlnd openSSL pcntl pcre PDO pdo_mysql pdo_pgsql pdo_sqlite pgsql Phar posix protobuf readline redis Reflection session shmop SimpleXML soap sockets sodium SPL sqlite3 standard swoole sysvmsg sysvsem sysvshm tokenizer xml xmlreader xmlrpc xmlwriter xsl Zend OPcache zip zlib None.
Use a non-built-in programming language
If you want to create a custom runtime by using a non-built-in language of the custom runtime, you must compress the parser or runtime of the language and your code file into a package and deploy the package in Function Compute. For example, if the runtime environment is Node.js 16, you must download the interpreter required for Node.js 16, compress the interpreter and your code file into a package, and then deploy the package in Function Compute. Perform the following steps:
- Download the Linux-x64 edition of
node
to the directory of the code package.wget http://mirrors.nju.edu.cn/nodejs/v16.14.2/node-v16.14.2-linux-x64.tar.gz -O node-v16.14.2-linux-x64.tar.gz && tar -zxvf node-v16.14.2-linux-x64.tar.gz && rm -rf node-v16.14.2-linux-x64.tar.gz
- Configure the startup command by which the custom runtime uses
node
.customRuntimeConfig: command: - /code/node-v16.14.2-linux-x64/bin/node args: - 'server.js' # You can also configure environment variables for the function: PATH=/code/node-v16.14.2-linux-x64/bin:/usr/local/bin/apache-maven/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/ruby/bin. # After the configuration, you can use node to start the HTTP server.
Install dependencies
For more information about how to install the dependencies of each language in a custom runtime, see the following documentation.
You can also use the layer feature of Function Compute to install dependencies. We recommend that you use an official common layer or build a dependency layer online. For more information, see the following topics: