All Products
Search
Document Center

Function Compute (2.0):Overview

Last Updated:Mar 15, 2024

This topic describes how to use a custom runtime to write functions in a Function Compute.

Background

Custom runtimes allow you to define runtime environments. In a custom runtime, you can define the runtime environment based on your business requirements.

  • 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

The following table shows the runtime environments that are supported by the custom runtime.

Parameter

Identifier

Operating System

Architecture

Custom runtime (Debian 10) (in public preview)

custom.debian10

Debian 10

x86_64

Custom Runtime

custom

Debian 9

x86_64

Custom runtime (Debian 10) (in public preview)

  • User permission: The function must be executed by the root user.

  • Directory permissions: All directories are writable.

  • The location of the code in the container: /code.

Custom Runtime

  • 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 location of the code in the container: /code.

Information about the runtime environment

Custom runtime (Debian10)

The following programming languages are built into a custom runtime of the Debian 10 type. You can create custom runtimes of the following languages without the need to install third-party interpreters or configure layers:

  • Python 2.7 (default Python version)

  • Python 3.10.9

Custom Runtime

A custom runtime supports the following built-in programming languages of the specified versions. You can create custom runtimes of the following languages without the need to install third-party interpreters or configure layers:

  • Python 3.7.4 (default Python version)

  • Node.js 10.16.2

  • OpenJDK 1.8.0

  • Ruby 2.7

  • Nginx 1.10.3

  • PHP 7.4.12

    Expand 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

    N/A

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. 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 is complete, you can directly use the 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: