alibabacloud-esa-pages-deploy

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Category: service
Category: service

ESA Functions & Pages — Edge Deployment & KV Storage

ESA Functions & Pages — 边缘部署与KV存储

Deploy to Alibaba Cloud ESA edge nodes via JavaScript SDK. Provides free global CDN acceleration and edge security protection, enabling your static assets to be served from the nearest edge node for improved performance and security.
  • Functions & Pages — Deploy edge functions and static content (same API, Pages is simplified pattern)
  • Edge KV — Distributed key-value storage accessible from edge functions
  • Free CDN — Global edge node acceleration, serve static assets from the nearest location
  • Security Protection — Built-in DDoS protection, WAF, and other edge security capabilities
通过JavaScript SDK部署到阿里云ESA边缘节点。提供免费的全球CDN加速和边缘安全防护,让您的静态资源可以从最近的边缘节点提供服务,从而提升性能和安全性。
  • Functions & Pages — 部署边缘函数和静态内容(API相同,Pages是简化模式)
  • Edge KV — 可从边缘函数访问的分布式键值存储
  • Free CDN — 全球边缘节点加速,从最近位置提供静态资源服务
  • Security Protection — 内置DDoS防护、WAF等边缘安全能力

Three Deployment Patterns

三种部署模式

PatternUse CaseCode TypeSize Limit
HTML PageQuick prototypes, single pagesAuto-wrapped JS< 5MB (ER limit)
Static DirectoryFrontend builds (React/Vue/etc.)Assets< 25MB per file
Custom FunctionAPI endpoints, dynamic logicCustom JS< 5MB
模式适用场景代码类型大小限制
HTML Page快速原型、单页面自动封装JS< 5MB (ER限制)
Static Directory前端构建产物(React/Vue/etc)资源文件单文件 < 25MB
Custom FunctionAPI端点、动态逻辑自定义JS< 5MB

Prerequisites

前置条件

Important: Enable ESA Functions & Pages first at ESA Console before using this skill, or use
OpenErService
API to enable programmatically.
bash
npm install @alicloud/esa20240910@2.43.0 @alicloud/openapi-client@0.4.15 @alicloud/credentials@2.4.4
重要: 使用本技能前请先在ESA控制台启用ESA Functions & Pages,或通过
OpenErService
API以编程方式启用。
bash
npm install @alicloud/esa20240910@2.43.0 @alicloud/openapi-client@0.4.15 @alicloud/credentials@2.4.4

Enable Edge Routine Service via API

通过API启用边缘例程服务

If the user hasn't enabled the Edge Routine service, call
OpenErService
to enable it:
javascript
// Check if service is enabled
const status = await client.getErService(
  new $Esa20240910.GetErServiceRequest({}),
);
if (status.body?.status !== "online") {
  // Enable the service
  await client.openErService(new $Esa20240910.OpenErServiceRequest({}));
}
如果用户尚未启用边缘例程服务,调用
OpenErService
进行启用:
javascript
// Check if service is enabled
const status = await client.getErService(
  new $Esa20240910.GetErServiceRequest({}),
);
if (status.body?.status !== "online") {
  // Enable the service
  await client.openErService(new $Esa20240910.OpenErServiceRequest({}));
}

SDK Quickstart

SDK快速入门

javascript
import Esa20240910, * as $Esa20240910 from "@alicloud/esa20240910";
import * as $OpenApi from "@alicloud/openapi-client";
import Credential from "@alicloud/credentials";

function createClient() {
  const credential = new Credential();
  const config = new $OpenApi.Config({
    credential,
    endpoint: "esa.cn-hangzhou.aliyuncs.com",
    userAgent: "AlibabaCloud-Agent-Skills",
  });
  return new Esa20240910(config);
}
javascript
import Esa20240910, * as $Esa20240910 from "@alicloud/esa20240910";
import * as $OpenApi from "@alicloud/openapi-client";
import Credential from "@alicloud/credentials";

function createClient() {
  const credential = new Credential();
  const config = new $OpenApi.Config({
    credential,
    endpoint: "esa.cn-hangzhou.aliyuncs.com",
    userAgent: "AlibabaCloud-Agent-Skills",
  });
  return new Esa20240910(config);
}

Unified Deployment Flow

统一部署流程

All deployments follow the same pattern:
1. CreateRoutine(name)              → Create function (skip if exists)
2. Upload code/assets to OSS        → Via staging upload or assets API
3. Commit & Publish                 → Deploy to staging → production
4. GetRoutine(name)                 → Get access URL (defaultRelatedRecord)
所有部署都遵循相同模式:
1. CreateRoutine(name)              → 创建函数(已存在则跳过)
2. Upload code/assets to OSS        → 通过暂存上传或资源API上传
3. Commit & Publish                 → 部署到预发环境 → 生产环境
4. GetRoutine(name)                 → 获取访问URL(defaultRelatedRecord字段)

HTML Page Flow

HTML页面部署流程

CreateRoutine → GetRoutineStagingCodeUploadInfo → Upload wrapped JS
→ CommitRoutineStagingCode → PublishRoutineCodeVersion(staging/production)
CreateRoutine → GetRoutineStagingCodeUploadInfo → 上传封装后的JS
→ CommitRoutineStagingCode → PublishRoutineCodeVersion(staging/production)

Static Directory Flow

静态目录部署流程

CreateRoutine → CreateRoutineWithAssetsCodeVersion → Upload zip
→ Poll GetRoutineCodeVersionInfo → CreateRoutineCodeDeployment(staging/production)
CreateRoutine → CreateRoutineWithAssetsCodeVersion → 上传zip包
→ 轮询 GetRoutineCodeVersionInfo → CreateRoutineCodeDeployment(staging/production)

Code Format

代码格式

All deployments ultimately run as Edge Routine code:
javascript
export default {
  async fetch(request) {
    return new Response("Hello", {
      headers: { "content-type": "text/html;charset=UTF-8" },
    });
  },
};
For HTML pages, your HTML is automatically wrapped into this format.
所有部署最终都以边缘例程代码的形式运行:
javascript
export default {
  async fetch(request) {
    return new Response("Hello", {
      headers: { "content-type": "text/html;charset=UTF-8" },
    });
  }
};
对于HTML页面,您的HTML会被自动封装为该格式。

Zip Package Structure

压缩包结构

TypeStructure
JS_ONLY
routine/index.js
ASSETS_ONLY
assets/*
(static files)
JS_AND_ASSETS
routine/index.js
+
assets/*
类型结构
JS_ONLY
routine/index.js
ASSETS_ONLY
assets/*
(静态文件)
JS_AND_ASSETS
routine/index.js
+
assets/*

API Summary

API概览

Edge Routine Service

边缘例程服务

  • Service Management:
    OpenErService
    ,
    GetErService
  • 服务管理:
    OpenErService
    ,
    GetErService

Functions & Pages

Functions & Pages

  • Function Management:
    CreateRoutine
    ,
    GetRoutine
    ,
    ListUserRoutines
  • Code Version:
    GetRoutineStagingCodeUploadInfo
    ,
    CommitRoutineStagingCode
    ,
    PublishRoutineCodeVersion
  • Assets Deployment:
    CreateRoutineWithAssetsCodeVersion
    ,
    GetRoutineCodeVersionInfo
    ,
    CreateRoutineCodeDeployment
  • Routes:
    CreateRoutineRoute
    ,
    ListRoutineRoutes
  • 函数管理:
    CreateRoutine
    ,
    GetRoutine
    ,
    ListUserRoutines
  • 代码版本:
    GetRoutineStagingCodeUploadInfo
    ,
    CommitRoutineStagingCode
    ,
    PublishRoutineCodeVersion
  • 资源部署:
    CreateRoutineWithAssetsCodeVersion
    ,
    GetRoutineCodeVersionInfo
    ,
    CreateRoutineCodeDeployment
  • 路由:
    CreateRoutineRoute
    ,
    ListRoutineRoutes

Edge KV

Edge KV

  • Namespace:
    CreateKvNamespace
    ,
    GetKvNamespace
    ,
    GetKvAccount
  • Key Operations:
    PutKv
    ,
    GetKv
    ,
    ListKvs
  • Batch Operations:
    BatchPutKv
  • High Capacity:
    PutKvWithHighCapacity
    ,
    BatchPutKvWithHighCapacity
  • 命名空间:
    CreateKvNamespace
    ,
    GetKvNamespace
    ,
    GetKvAccount
  • 键操作:
    PutKv
    ,
    GetKv
    ,
    ListKvs
  • 批量操作:
    BatchPutKv
  • 大容量支持:
    PutKvWithHighCapacity
    ,
    BatchPutKvWithHighCapacity

Utility Scripts

实用脚本

Pre-made scripts for common operations. Install dependencies first:
bash
npm install @alicloud/esa20240910@2.43.0 @alicloud/openapi-client@0.4.15 @alicloud/credentials@2.4.4 @alicloud/tea-util@1.4.9 jszip@3.10.1
ScriptUsageDescription
deploy-html.mjs
node scripts/deploy-html.mjs <name> <html-file>
Deploy HTML page
deploy-folder.mjs
node scripts/deploy-folder.mjs <name> <folder>
Deploy static directory
deploy-function.mjs
node scripts/deploy-function.mjs <name> <code-file>
Deploy custom function
manage.mjs
node scripts/manage.mjs list|get
Manage routines
Examples:
bash
undefined
针对常见操作的预制脚本。请先安装依赖:
bash
npm install @alicloud/esa20240910@2.43.0 @alicloud/openapi-client@0.4.15 @alicloud/credentials@2.4.4 @alicloud/tea-util@1.4.9 jszip@3.10.1
脚本用法说明
deploy-html.mjs
node scripts/deploy-html.mjs <name> <html-file>
部署HTML页面
deploy-folder.mjs
node scripts/deploy-folder.mjs <name> <folder>
部署静态目录
deploy-function.mjs
node scripts/deploy-function.mjs <name> <code-file>
部署自定义函数
manage.mjs
node scripts/manage.mjs list|get
管理例程
示例:
bash
undefined

Deploy HTML page

部署HTML页面

node scripts/deploy-html.mjs my-page index.html
node scripts/deploy-html.mjs my-page index.html

Deploy React/Vue build

部署React/Vue构建产物

node scripts/deploy-folder.mjs my-app ./dist
node scripts/deploy-folder.mjs my-app ./dist

Deploy custom function

部署自定义函数

node scripts/deploy-function.mjs my-api handler.js
node scripts/deploy-function.mjs my-api handler.js

List all routines

列出所有例程

node scripts/manage.mjs list
node scripts/manage.mjs list

Get routine details

获取例程详情

node scripts/manage.mjs get my-page
undefined
node scripts/manage.mjs get my-page
undefined

Key Notes

注意事项

  • Function name: lowercase letters/numbers/hyphens, start with letter, length ≥ 2
  • Same name: Reuses existing function, deploys new version
  • Environments: staging → production (both by default)
  • Access URL:
    defaultRelatedRecord
    from
    GetRoutine
  • Size limits: Functions < 5MB, Assets single file < 25MB, KV value < 2MB (25MB high capacity)
  • 函数名称: 小写字母/数字/连字符,字母开头,长度≥2
  • 同名处理: 复用已有函数,部署新版本
  • 环境: 预发环境 → 生产环境(默认同时部署两者)
  • 访问URL: 来自
    GetRoutine
    返回的
    defaultRelatedRecord
    字段
  • 大小限制: 函数< 5MB,资源单文件< 25MB,KV值< 2MB(大容量模式支持25MB)

Credentials

凭证

The SDK uses Alibaba Cloud default credential chain. No explicit AK/SK configuration needed.
Note: ESA endpoint is fixed (
esa.cn-hangzhou.aliyuncs.com
), no region needed.
SDK使用阿里云默认凭证链,无需显式配置AK/SK。
注意: ESA endpoint是固定的(
esa.cn-hangzhou.aliyuncs.com
),无需指定地域。

Reference

参考文档

  • Functions & Pages API:
    references/pages-api.md
  • Edge KV API:
    references/kv-api.md
  • Functions & Pages API:
    references/pages-api.md
  • Edge KV API:
    references/kv-api.md