Cloud Computing 16 min read

Implementing Custom Runtime and Custom Container Runtime for Alibaba Cloud Function Compute with TypeScript

This article explains how to build a custom serverless runtime and a custom container runtime on Alibaba Cloud Function Compute, covering the background of FaaS, the concept of custom runtimes, step‑by‑step development using TypeScript, Docker, and deployment with the Fun tool.

政采云技术
政采云技术
政采云技术
Implementing Custom Runtime and Custom Container Runtime for Alibaba Cloud Function Compute with TypeScript

The article introduces Serverless (FaaS + BaaS) and explains that cloud providers offer limited standard runtimes, so developers can use Custom Runtime to create fully user‑defined execution environments for any language or version.

Using Alibaba Cloud Function Compute (FC) as an example, it lists the officially supported languages and versions, showing that Node.js and TypeScript are not fully supported, which motivates the need for a custom runtime.

Custom Runtime Concept : a user‑provided HTTP server with a bootstrap entry file that takes over all function‑compute requests. The article demonstrates a TypeScript runtime where the server is written in server.ts and listens on 0.0.0.0:9000 .

import * as http from 'http';
const server = http.createServer(function (req: http.IncomingMessage, res: http.ServerResponse): void {
  const rid = req.headers["x-fc-request-id"];
  console.log(`FC Invoke Start RequestId: ${rid}`);
  let rawData = "";
  req.on('data', function (chunk) { rawData += chunk; });
  req.on('end', function () {
    console.log(rawData);
    res.writeHead(200);
    res.end(rawData);
    console.log(`FC Invoke End RequestId: ${rid}`);
  });
});
server.timeout = 0;
server.keepAliveTimeout = 0;
server.listen(9000, '0.0.0.0', function () {
  console.log('FunctionCompute typescript runtime inited.');
});

A bootstrap script simply runs the TypeScript server with ts-node :

#!/bin/bash
./node_modules/.bin/ts-node server.ts

The deployment configuration is defined in template.yaml , specifying a custom runtime, handler placeholder, memory, and code URI.

ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Resources:
  custom-runtime-ts:
    Type: 'Aliyun::Serverless::Function'
    Properties:
      Handler: index.handler
      Runtime: custom
      MemorySize: 512
      CodeUri: './'

After installing the Fun CLI ( npm install @alicloud/fun -g ) and configuring credentials, the article shows how to deploy with fun deploy -y and test the function using fun invoke -e "hello,my custom runtime" or curl against the local server.

For scenarios where a specific Node version is required, the article moves to Custom Container Runtime . It explains that the platform runs containers (Docker) and provides a Dockerfile that builds a Node 16.1.0 image, copies the application, installs dependencies, and sets the entry point.

# Dockerfile
FROM node:16.1.0-alpine3.11
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
ENTRYPOINT ["node", "server.js"]

After building and pushing the image to Alibaba Cloud Container Registry, a new template.yaml is created for the custom container function, specifying Runtime: custom-container , the image URL, command, args, and an HTTP trigger.

Resources:
  CustomContainerRuntime:
    Type: 'Aliyun::Serverless::Service'
    Properties:
      Policies:
        - AliyunContainerRegistryReadOnlyAccess
      InternetAccess: true
    nodejs-express-http:
      Type: 'Aliyun::Serverless::Function'
      Properties:
        Runtime: custom-container
        CAPort: 9000
        Handler: not-used
        MemorySize: 1024
        CodeUri: ./
        CustomContainerConfig:
          Image: 'registry.cn-hangzhou.aliyuncs.com/my_serverless/nodejs:v16.1.0'
          Command: '[ "node" ]'
          Args: '["server.js"]'
        Events:
          http-trigger-test:
            Type: HTTP
            Properties:
              AuthType: ANONYMOUS
              Methods: ['GET','POST','PUT']

Deploying this configuration with fun deploy -y creates a function that runs the custom container; invoking it via the HTTP trigger returns the runtime version, confirming the success of both custom runtime and custom container runtime implementations.

The article concludes that custom (container) runtimes break language restrictions of FaaS platforms, enable one‑click migration of existing web applications, and improve developer experience and delivery efficiency.

DockerserverlesstypescriptcontainerAlibaba CloudFunction ComputeCustom Runtime
政采云技术
Written by

政采云技术

ZCY Technology Team (Zero), based in Hangzhou, is a growth-oriented team passionate about technology and craftsmanship. With around 500 members, we are building comprehensive engineering, project management, and talent development systems. We are committed to innovation and creating a cloud service ecosystem for government and enterprise procurement. We look forward to your joining us.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.