Cloud Native 7 min read

Deploy a Static Website on Alibaba Cloud Function Compute Using a Custom Runtime

This guide walks you through creating a simple Express‑based HTTP server, packaging it with a bootstrap script, configuring the @serverless-devs/s tool and an s.yaml file, and finally deploying the static site to Alibaba Cloud Function Compute with a custom domain.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Deploy a Static Website on Alibaba Cloud Function Compute Using a Custom Runtime

Overview

Alibaba Cloud Function Compute (FC) provides 500 MB built‑in storage, sufficient for static assets. The article describes how to package a static site built in the dist directory and run it on FC using a custom runtime.

Step 1 – Create a simple HTTP server

Install Express and create app.js that serves the dist folder and redirects any unknown request to the site root.

let Express = require("express");
let app = new Express();
app.use(Express.static('dist'));
// redirect unmatched requests to the site root
app.use((req, res) => { res.redirect("/"); });
let port = 9000;
app.listen(port, () => { console.log(`App started on port ${port}`); });

Run node app.js locally and verify that http://localhost:9000/dist/index.html is reachable.

Step 2 – Add a bootstrap script for the custom runtime

FC custom runtime requires a bootstrap file that starts the process. Create a file named bootstrap with the following content (the shebang line is mandatory):

#! /bin/bash
node app.js

On Windows convert line endings from \r\n to \n to avoid start‑up timeouts.

Step 3 – Install Serverless Devs CLI and define s.yaml

Install the CLI as a development dependency: yarn add @serverless-devs/s -D Create s.yaml with the minimal configuration required to deploy the function:

edition: 1.0.0
name: my-awesome-website-project
services:
  my-service:
    component: devsapp/fc
    props:
      region: cn-shenzhen
      service:
        name: my-awesome-websites
      function:
        name: www-example-com
        runtime: custom
        handler: dummy-handler   # placeholder for custom runtime
        codeUri: ./               # deploy the current directory
      triggers:
        - name: http
          type: http
          config:
            authType: anonymous
            methods: [ HEAD, GET ]

Step 4 – Deploy the site

Configure your Alibaba Cloud AccessKey and AccessSecret (see Alibaba Cloud documentation). Then execute: s deploy The function is created, the bootstrap script launches the Express server, and the static files in dist become accessible via the HTTP trigger.

Step 5 – Bind a custom domain

Add a CNAME record that points to ${UID}.${REGION}.fc.aliyuncs.com (for the example region cn-shenzhen the target is xxxxx.cn-shenzhen.fc.aliyuncs.com). In the FC console create a custom domain, bind it to the HTTP trigger, and wait for DNS propagation. After that the site can be accessed with the custom domain, e.g. http://deploy-static-website-to-fc.example.dengchao.fun.

Sample project

The complete example is available on GitHub:

https://github.com/DevDengChao/deploy-static-website-to-fc-example

Reference images

Domain configuration screenshot
Domain configuration screenshot
FC console custom domain setup
FC console custom domain setup

Additional references

FC resource limits: https://help.aliyun.com/document_detail/51907.html

Configure AccessKey/Secret: https://www.serverless-devs.com/serverless-devs/command/config

FC product overview: https://help.aliyun.com/document_detail/52895.html

Custom runtime documentation: https://help.aliyun.com/document_detail/132044.html

Custom domain setup guide: https://help.aliyun.com/document_detail/90763.html

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ServerlessDeploymentAlibaba CloudFunction ComputeStatic WebsiteCustom Runtime
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

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.