All Products
Search
Document Center

Function Compute (2.0):Overview

Last Updated:Jun 11, 2024

This topic describes custom runtimes in which you can write functions in Function Compute.

Background

Custom runtimes allow you to customize runtime environments. In a custom runtime, you can create an exclusive function execution environment based on your business requirements. The following items list common scenarios:

  • Customize an individualized programming language, such as Rust.

  • Customize a runtime based on a specified version of a programming language, such as Node.js 16.

Container environments

The following table shows the execution environments that are supported by custom runtimes in Function Compute.

Runtime

Identifier

OS

Architecture

Custom runtimes (Debian10)

custom.debian10

Debian 10

x86_64

Custom runtimes (Debian 9)

custom

Debian 9

x86_64

Custom runtimes (Debian 10) (in public preview)

  • User permissions: Functions must be executed by root users.

  • Directory permissions: Data can be written to any directories.

  • Code location in the container: /code

Custom runtimes (Debian 9)

  • User permissions

    • Functions that are created at and after 00:00:00 December 1, 2021 must be executed by root users.

    • Functions that are created before 00:00:00 December 1, 2021 must be executed by non-root users.

  • Directory permissions

    • For functions that are created at and after 00:00:00 December 1, 2021, data can be written to any directories.

    • For functions that are created before 00:00:00 December 1, 2021, data can be written only to the /tmp directory.

  • Code location in the container: /code

Environment information

Custom runtimes (Debian10)

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

The following table describes the details. For some programming languages, environment variables must be configured.

Programming language

Installation directory

Version

Environment variable

Node.js 20

/var/fc/lang/nodejs20

v20.10.0

PATH=/var/fc/lang/nodejs20/bin:$PATH

Node.js 18

/var/fc/lang/nodejs18

v18.19.0

PATH=/var/fc/lang/nodejs18/bin:$PATH

Python 3.10

/var/fc/lang/python3.10

3.10.9

PATH=/var/fc/lang/python3.10/bin:$PATH

Python 2.7

Default installation directory in the system

2.7.16

N/A

Custom runtimes ( Debian 9)

The following programming languages are built into Debian 9-based custom runtimes. You can create custom runtimes of the following programming 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 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

    N/A

Use a non-built-in programming language

Note

We recommend that you use a public layer if you want to use a non-built-in programming language. For more information, see Configure common layers by using the console.

If you want to create a custom runtime by using a non-built-in programming language, you must compress the interpreter or runtime of the language and your code file into a package and deploy the package in Function Compute so that your functions can run as expected. For example, if you want to use 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 operations:

  1. Download Node.js of a 64-bit Linux version to the code package directory.

    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 of Node.js in the custom runtime.

    customRuntimeConfig:
      command:
        - /code/node-v16.14.2-linux-x64/bin/node
      args:
        - 'server.js'
    
    # You can also configure the following 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 Node.js to start an HTTP server. 

Install dependencies

For more information about how to install dependencies of each language in a custom runtime, see the following topics:

You can also use layers of Function Compute to install dependencies. We recommend that you use a public layer or build a dependency layer online. For more information, see the following topics: