alibabacloud-esa-pages-deploy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCategory: 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
三种部署模式
| 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 |
| 模式 | 适用场景 | 代码类型 | 大小限制 |
|---|---|---|---|
| HTML Page | 快速原型、单页面 | 自动封装JS | < 5MB (ER限制) |
| Static Directory | 前端构建产物(React/Vue/etc) | 资源文件 | 单文件 < 25MB |
| Custom Function | API端点、动态逻辑 | 自定义JS | < 5MB |
Prerequisites
前置条件
Important: Enable ESA Functions & Pages first at ESA Console before using this skill, or useAPI to enable programmatically.OpenErService
bash
npm install @alicloud/esa20240910@2.43.0 @alicloud/openapi-client@0.4.15 @alicloud/credentials@2.4.4重要: 使用本技能前请先在ESA控制台启用ESA Functions & Pages,或通过API以编程方式启用。OpenErService
bash
npm install @alicloud/esa20240910@2.43.0 @alicloud/openapi-client@0.4.15 @alicloud/credentials@2.4.4Enable Edge Routine Service via API
通过API启用边缘例程服务
If the user hasn't enabled the Edge Routine service, call to enable it:
OpenErServicejavascript
// 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({}));
}如果用户尚未启用边缘例程服务,调用进行启用:
OpenErServicejavascript
// 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
压缩包结构
| Type | Structure |
|---|---|
| JS_ONLY | |
| ASSETS_ONLY | |
| JS_AND_ASSETS | |
| 类型 | 结构 |
|---|---|
| JS_ONLY | |
| ASSETS_ONLY | |
| JS_AND_ASSETS | |
API Summary
API概览
Edge Routine Service
边缘例程服务
- Service Management: ,
OpenErServiceGetErService
- 服务管理: ,
OpenErServiceGetErService
Functions & Pages
Functions & Pages
- Function Management: ,
CreateRoutine,GetRoutineListUserRoutines - Code Version: ,
GetRoutineStagingCodeUploadInfo,CommitRoutineStagingCodePublishRoutineCodeVersion - Assets Deployment: ,
CreateRoutineWithAssetsCodeVersion,GetRoutineCodeVersionInfoCreateRoutineCodeDeployment - Routes: ,
CreateRoutineRouteListRoutineRoutes
- 函数管理: ,
CreateRoutine,GetRoutineListUserRoutines - 代码版本: ,
GetRoutineStagingCodeUploadInfo,CommitRoutineStagingCodePublishRoutineCodeVersion - 资源部署: ,
CreateRoutineWithAssetsCodeVersion,GetRoutineCodeVersionInfoCreateRoutineCodeDeployment - 路由: ,
CreateRoutineRouteListRoutineRoutes
Edge KV
Edge KV
- Namespace: ,
CreateKvNamespace,GetKvNamespaceGetKvAccount - Key Operations: ,
PutKv,GetKvListKvs - Batch Operations:
BatchPutKv - High Capacity: ,
PutKvWithHighCapacityBatchPutKvWithHighCapacity
- 命名空间: ,
CreateKvNamespace,GetKvNamespaceGetKvAccount - 键操作: ,
PutKv,GetKvListKvs - 批量操作:
BatchPutKv - 大容量支持: ,
PutKvWithHighCapacityBatchPutKvWithHighCapacity
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| Script | Usage | Description |
|---|---|---|
| | Deploy HTML page |
| | Deploy static directory |
| | Deploy custom function |
| | 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| 脚本 | 用法 | 说明 |
|---|---|---|
| | 部署HTML页面 |
| | 部署静态目录 |
| | 部署自定义函数 |
| | 管理例程 |
示例:
bash
undefinedDeploy 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
undefinednode scripts/manage.mjs get my-page
undefinedKey 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: from
defaultRelatedRecordGetRoutine - 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 (), no region needed.esa.cn-hangzhou.aliyuncs.com
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