Alibabacloud Esa Pages Deploy
by @sdk-team
Deploy HTML pages, static directories, or custom edge functions to Alibaba Cloud ESA edge nodes. Manage Edge KV for distributed key-value storage. Use when d...
clawhub install alibabacloud-esa-pages-deployπ About This Skill
name: alibabacloud-esa-pages-deploy description: Deploy HTML pages, static directories, or custom edge functions to Alibaba Cloud ESA edge nodes. Manage Edge KV for distributed key-value storage. Use when deploying web pages, static sites, frontend builds, serverless edge functions, or edge data storage to ESA Functions & Pages.
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.
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.
npm install @alicloud/esa20240910@2.43.0 @alicloud/openapi-client@0.4.15 @alicloud/credentials@2.4.4
Enable Edge Routine Service via API
If the user hasn't enabled the Edge Routine service, call OpenErService to enable it:
// 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
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)
HTML Page Flow
CreateRoutine β GetRoutineStagingCodeUploadInfo β Upload wrapped JS
β CommitRoutineStagingCode β PublishRoutineCodeVersion(staging/production)
Static Directory Flow
CreateRoutine β CreateRoutineWithAssetsCodeVersion β Upload zip
β Poll GetRoutineCodeVersionInfo β CreateRoutineCodeDeployment(staging/production)
Code Format
All deployments ultimately run as Edge Routine code:
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.
Zip Package Structure
| Type | Structure |
| ----------------- | ------------------------------- |
| JS_ONLY | routine/index.js |
| ASSETS_ONLY | assets/* (static files) |
| JS_AND_ASSETS | routine/index.js + assets/* |
API Summary
Edge Routine Service
OpenErService, GetErServiceFunctions & Pages
CreateRoutine, GetRoutine, ListUserRoutinesGetRoutineStagingCodeUploadInfo, CommitRoutineStagingCode, PublishRoutineCodeVersionCreateRoutineWithAssetsCodeVersion, GetRoutineCodeVersionInfo, CreateRoutineCodeDeploymentCreateRoutineRoute, ListRoutineRoutesEdge KV
CreateKvNamespace, GetKvNamespace, GetKvAccountPutKv, GetKv, ListKvsBatchPutKvPutKvWithHighCapacity, BatchPutKvWithHighCapacityUtility Scripts
Pre-made scripts for common operations. Install dependencies first:
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.mjs | node scripts/deploy-html.mjs | Deploy HTML page |
| deploy-folder.mjs | node scripts/deploy-folder.mjs | Deploy static directory |
| deploy-function.mjs | node scripts/deploy-function.mjs | Deploy custom function |
| manage.mjs | node scripts/manage.mjs list\|get | Manage routines |
Examples:
# Deploy HTML page
node scripts/deploy-html.mjs my-page index.htmlDeploy React/Vue build
node scripts/deploy-folder.mjs my-app ./distDeploy custom function
node scripts/deploy-function.mjs my-api handler.jsList all routines
node scripts/manage.mjs listGet routine details
node scripts/manage.mjs get my-page
Key Notes
defaultRelatedRecord from GetRoutineCredentials
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
references/pages-api.mdreferences/kv-api.mdβοΈ Configuration
> Important: Enable ESA Functions & Pages first at ESA Console before using this skill, or use OpenErService API to enable programmatically.
npm install @alicloud/esa20240910@2.43.0 @alicloud/openapi-client@0.4.15 @alicloud/credentials@2.4.4
Enable Edge Routine Service via API
If the user hasn't enabled the Edge Routine service, call OpenErService to enable it:
// 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({}));
}