Deploy a Deno Web App on Alibaba Cloud Serverless with One-Click Automation
This guide explains how to leverage Alibaba Cloud Serverless and the Deno runtime to quickly migrate, build, and deploy a TypeScript‑based web application, covering the benefits of serverless, Deno advantages, code examples, configuration files, and step‑by‑step deployment commands.
Why Serverless?
Serverless offers horizontal scaling and pay‑as‑you‑go pricing, allowing developers to focus on business logic rather than infrastructure management, which improves development efficiency and reduces costs.
Migration Options to Serverless
Four common approaches are supported on Alibaba Cloud Serverless:
Directly run script languages (runtime already provided).
Runtime + language scripts (upload everything).
Executable files (compile locally, then upload).
Custom containers (Docker images).
Custom runtimes provide the best compatibility; this guide uses a custom runtime based on Deno.
Why Choose Deno?
Deno is a modern JavaScript/TypeScript runtime built with Rust, offering native TypeScript support, better ECMAScript compatibility, and built‑in web APIs (e.g., fetch, crypto) without needing npm. It can compile to a single executable, simplifying deployment.
Simple Deno Web Application Example
The following TypeScript code creates a tiny web server that returns a greeting, the request method, URL, and user‑agent header.
import { serve } from "https://deno.land/[email protected]/http/server.ts";
function handler(req: Request): Response {
return new Response([
"Hello, World!",
req.method,
req.url,
req.headers.get("user-agent")
].join("
"));
}
serve(handler, { port: 9000 });Save this file as /User/zsqk/web/main.ts.
Creating the Serverless Function
In the Alibaba Cloud Function Compute console, create a service and then a function using the "Custom Runtime for Smooth Web Server Migration" option. Record the service name, function name, and generated domain name.
One‑Click Deployment with Serverless Devs
Create a s.yaml configuration file (place it in /User/zsqk/web/) with the following content, replacing placeholders with your actual region, service name, and function name:
edition: 1.0.0
name: zsqk-fc
access: default
services:
fc-z1-deno:
component: devsapp/fc
props:
region: ${region}
service:
name: ${service_name}
function:
name: ${function_name}
instanceConcurrency: 5
instanceType: e1
memorySize: 128
runtime: custom
timeout: 3
codeUri: "./dist"Build and Upload Commands
Navigate to /User/zsqk/web/ and run the following Deno commands to compile the TypeScript file into a Linux executable and prepare the bootstrap script:
// Build deno executable
const r = Deno.run({
cmd: [
`deno`,
"compile",
"--output",
"dist/bin/zsqk",
"--target",
"x86_64-unknown-linux-gnu",
"--allow-all",
"/User/zsqk/web/main.ts",
],
});
await r.status();
r.close();
Deno.writeTextFileSync(
`/User/zsqk/web/dist/bootstrap`,
"#!/bin/bash
./bin/zsqk --allow-all"
);Then upload the built artifact using Serverless Devs:
// Prepare upload
const r = Deno.run({
cmd: ["s", "deploy", "function", "--use-local"],
});
await r.status();
r.close();When the commands complete successfully, the Deno web application is deployed to Alibaba Cloud Serverless. Access the configured domain to verify that the UA‑display service works.
Iterating After Deployment
For subsequent code changes, repeat the build and deployment steps; no additional configuration is required.
Original article: https://developer.aliyun.com/article/986503
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
