Category: service
ESA Functions & Pages — Edge Deployment & KV Storage
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
Three Deployment Patterns
| Pattern | Use Case | Code Type | Size Limit |
|---|
| HTML Page | Quick prototypes, single pages | Auto-wrapped JS | < 5MB (ER limit) |
| Static Directory |
Frontend builds (React/Vue/etc.) | Assets |
< 25MB per file |
|
Custom Function | API endpoints, dynamic logic | Custom JS |
< 5MB |
Prerequisites
Important: Enable ESA Functions & Pages first at ESA Console before using this skill, or use OpenErService API to enable programmatically.
CODEBLOCK0
Enable Edge Routine Service via API
If the user hasn't enabled the Edge Routine service, call OpenErService to enable it:
CODEBLOCK1
SDK Quickstart
CODEBLOCK2
Unified Deployment Flow
All deployments follow the same pattern:
CODEBLOCK3
HTML Page Flow
CODEBLOCK4
Static Directory Flow
CODEBLOCK5
Code Format
All deployments ultimately run as Edge Routine code:
CODEBLOCK6
For HTML pages, your HTML is automatically wrapped into this format.
Zip Package Structure
| Type | Structure |
|---|
| JSONLY | INLINECODE2 |
| ASSETSONLY |
assets/* (static files) |
|
JSANDASSETS |
routine/index.js +
assets/* |
API Summary
Edge Routine Service
- - Service Management:
OpenErService, INLINECODE7
Functions & Pages
- - Function Management:
CreateRoutine, GetRoutine, INLINECODE10 - Code Version:
GetRoutineStagingCodeUploadInfo, CommitRoutineStagingCode, INLINECODE13 - Assets Deployment:
CreateRoutineWithAssetsCodeVersion, GetRoutineCodeVersionInfo, INLINECODE16 - Routes:
CreateRoutineRoute, INLINECODE18
Edge KV
- - Namespace:
CreateKvNamespace, GetKvNamespace, INLINECODE21 - Key Operations:
PutKv, GetKv, INLINECODE24 - Batch Operations: INLINECODE25
- High Capacity:
PutKvWithHighCapacity, INLINECODE27
Utility Scripts
Pre-made scripts for common operations. Install dependencies first:
CODEBLOCK7
| Script | Usage | Description |
|---|
| INLINECODE28 | INLINECODE29 | Deploy HTML page |
| INLINECODE30 |
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:
CODEBLOCK8
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 INLINECODE37 - Size limits: Functions < 5MB, Assets single file < 25MB, KV value < 2MB (25MB high capacity)
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.
Reference
- - Functions & Pages API: INLINECODE39
- Edge KV API: INLINECODE40
技能名称: alibabacloud-esa-pages-deploy
详细描述:
类别: 服务
ESA Functions & Pages — 边缘部署与KV存储
通过JavaScript SDK部署到阿里云ESA边缘节点。提供免费的全球CDN加速和边缘安全防护,使您的静态资源能够从最近的边缘节点提供服务,从而提升性能和安全性。
- - Functions & Pages — 部署边缘函数和静态内容(相同API,Pages为简化模式)
- Edge KV — 边缘函数可访问的分布式键值存储
- 免费CDN — 全球边缘节点加速,从最近位置提供静态资源
- 安全防护 — 内置DDoS防护、WAF及其他边缘安全能力
三种部署模式
| 模式 | 使用场景 | 代码类型 | 大小限制 |
|---|
| HTML页面 | 快速原型、单页面 | 自动包装的JS | < 5MB (ER限制) |
| 静态目录 |
前端构建产物 (React/Vue等) | 静态资源 |
< 25MB 每文件 |
|
自定义函数 | API端点、动态逻辑 | 自定义JS |
< 5MB |
前提条件
重要:使用此技能前,请先在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
通过API启用边缘函数服务
如果用户尚未启用边缘函数服务,调用OpenErService进行启用:
javascript
// 检查服务是否已启用
const status = await client.getErService(
new $Esa20240910.GetErServiceRequest({}),
);
if (status.body?.status !== online) {
// 启用服务
await client.openErService(new $Esa20240910.OpenErServiceRequest({}));
}
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);
}
统一部署流程
所有部署遵循相同模式:
- 1. CreateRoutine(name) → 创建函数(若已存在则跳过)
- 上传代码/资源到OSS → 通过预发布上传或资源API
- 提交并发布 → 部署到预发布环境 → 生产环境
- GetRoutine(name) → 获取访问URL (defaultRelatedRecord)
HTML页面流程
CreateRoutine → GetRoutineStagingCodeUploadInfo → 上传包装后的JS
→ CommitRoutineStagingCode → PublishRoutineCodeVersion(预发布/生产)
静态目录流程
CreateRoutine → CreateRoutineWithAssetsCodeVersion → 上传zip包
→ 轮询 GetRoutineCodeVersionInfo → CreateRoutineCodeDeployment(预发布/生产)
代码格式
所有部署最终以边缘函数代码形式运行:
javascript
export default {
async fetch(request) {
return new Response(Hello, {
headers: { content-type: text/html;charset=UTF-8 },
});
},
};
对于HTML页面,您的HTML会自动包装为此格式。
Zip包结构
| 类型 | 结构 |
|---|
| JSONLY | routine/index.js |
| ASSETSONLY |
assets/* (静态文件) |
|
JSANDASSETS | routine/index.js + assets/* |
API摘要
边缘函数服务
- - 服务管理: OpenErService, GetErService
Functions & Pages
- - 函数管理: CreateRoutine, GetRoutine, ListUserRoutines
- 代码版本: GetRoutineStagingCodeUploadInfo, CommitRoutineStagingCode, PublishRoutineCodeVersion
- 资源部署: CreateRoutineWithAssetsCodeVersion, GetRoutineCodeVersionInfo, CreateRoutineCodeDeployment
- 路由: CreateRoutineRoute, ListRoutineRoutes
Edge KV
- - 命名空间: CreateKvNamespace, GetKvNamespace, GetKvAccount
- 键操作: PutKv, GetKv, ListKvs
- 批量操作: BatchPutKv
- 大容量: PutKvWithHighCapacity, BatchPutKvWithHighCapacity
实用脚本
预置脚本用于常见操作。请先安装依赖:
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 <名称> <html文件> | 部署HTML页面 |
| deploy-folder.mjs |
node scripts/deploy-folder.mjs <名称> <文件夹> | 部署静态目录 |
| deploy-function.mjs | node scripts/deploy-function.mjs <名称> <代码文件> | 部署自定义函数 |
| manage.mjs | node scripts/manage.mjs list\|get | 管理函数 |
示例:
bash
部署HTML页面
node scripts/deploy-html.mjs my-page index.html
部署React/Vue构建产物
node scripts/deploy-folder.mjs my-app ./dist
部署自定义函数
node scripts/deploy-function.mjs my-api handler.js
列出所有函数
node scripts/manage.mjs list
获取函数详情
node scripts/manage.mjs get my-page
关键说明
- - 函数名称:小写字母/数字/连字符,以字母开头,长度≥2
- 同名函数:复用已有函数,部署新版本
- 环境:预发布环境 → 生产环境(默认两者)
- 访问URL:GetRoutine返回的defaultRelatedRecord
- 大小限制:函数<5MB,资源单文件<25MB,KV值<2MB(大容量模式25MB)
凭证
SDK使用阿里云默认凭证链。无需显式配置AK/SK。
注意:ESA端点固定(esa.cn-hangzhou.aliyuncs.com),无需指定地域。
参考
- - Functions & Pages API: references/pages-api.md
- Edge KV API: references/kv-api.md