This topic describes the custom runtimes in which you can write function code in Function Compute.

Background information

Custom runtimes allow you to define runtime environments. In a custom runtime, you can define the runtime environment based on your business requirements. For example, you can perform the following operations:
  • Use a specified programming language, such as Rust.
  • Use a runtime environment of the 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:
    • The functions that are created at or after 00:00:00 on December 1, 2021 must be executed by the root user.
    • The functions that are created before 00:00:00 on December 1, 2021 must be executed by a non-root user.
  • Directory permissions:
    • For the functions that are created at and after 00:00:00 December 1, 2021, data can be written to all the directories.
    • 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.12
    The following table describes the built-in extensions of PHP 7.4.12.
    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:

  1. 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
  2. Use node in the startup command of the custom runtime.
    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.
    # This way, you can use node to start the HTTP server.