Category: tool
Function Compute (FC 3.0) Serverless Devs
Goals
- - Install and validate Serverless Devs.
- Configure credentials, initialize example project, deploy, invoke, and remove.
- Provide CLI flow with Python runtime example.
Quick Start Flow
- 1. Install Node.js (14+) and npm.
- Install and validate Serverless Devs.
- Configure credentials via guided setup.
- Initialize example project and enter directory.
- Deploy, invoke, and optionally remove.
Install Serverless Devs (npm)
Global install (requires sudo):
CODEBLOCK0
No-sudo alternative (recommended in restricted environments):
CODEBLOCK1
Configure Credentials (guided)
CODEBLOCK2
Choose Alibaba Cloud (alibaba), provide AccountID, AccessKeyID, AccessKeySecret, and set alias.
Configure Credentials (command)
Use CLI args to configure credential alias in one command (non-interactive):
CODEBLOCK3
If using environment variables, inject them into the command (example):
CODEBLOCK4
Or use Serverless Devs convention JSON environment variable (example):
CODEBLOCK5
Reference in s.yaml:
CODEBLOCK6
Initialize Example (Python)
CODEBLOCK7
Initialization creates s.yaml, code/, and readme.md; edit code/index.py for function logic.
Deploy, Invoke, and Remove
CODEBLOCK8
Custom Domain Binding (Avoid Default Domain Forced Download)
Note: FC default domain adds Content-Disposition: attachment, causing browser downloads.
Use a custom domain to avoid this behavior.
Step 1: Configure CNAME for your domain
Configure DNS CNAME to FC public CNAME:
CODEBLOCK9
Example (Hangzhou region):
CODEBLOCK10
Note: if using apex domain (e.g. animus.run) and DNS provider does not support CNAME at apex,
use ALIAS/ANAME records, or switch to a subdomain such as www.animus.run.
Step 2: Create custom domain in Serverless Devs
Option A: add fc3-domain resource in s.yaml:
CODEBLOCK11
INLINECODE14 is example default; ask user when the best region is unclear.
Then deploy:
CODEBLOCK12
Option B: use Console (Advanced Features > Custom Domains) to create and route custom domain.
Common Errors
- -
DomainNameNotResolved: domain not resolved to correct FC CNAME. - INLINECODE16 : mainland China regions require ICP filing associated with Alibaba Cloud.
References
- - See
references/install_serverless_devs_and_docker.md for detailed official steps. - HTTP trigger limitations and response header behavior (default domain enforces Content-Disposition: attachment)
- https://www.alibabacloud.com/help/en/functioncompute/fc/user-guide/http-triggers-overview
- - Custom domain binding and CNAME guidance
- https://www.alibabacloud.com/help/en/functioncompute/fc/user-guide/configure-custom-domain-names
- - Official source list: INLINECODE18
Validation
CODEBLOCK13
Pass criteria: command exits 0 and output/aliyun-fc-serverless-devs/validate.txt is generated.
Output And Evidence
- - Save artifacts, command outputs, and API response summaries under
output/aliyun-fc-serverless-devs/. - Include key parameters (region/resource id/time range) in evidence files for reproducibility.
Prerequisites
- - Configure least-privilege Alibaba Cloud credentials before execution.
- Prefer environment variables:
ALICLOUD_ACCESS_KEY_ID, ALICLOUD_ACCESS_KEY_SECRET, optional ALICLOUD_REGION_ID. - If region is unclear, ask the user before running mutating operations.
Workflow
1) Confirm user intent, region, identifiers, and whether the operation is read-only or mutating.
2) Run one minimal read-only query first to verify connectivity and permissions.
3) Execute the target operation with explicit parameters and bounded scope.
4) Verify results and save output/evidence files.
分类:工具
函数计算(FC 3.0)Serverless Devs
目标
- - 安装并验证 Serverless Devs。
- 配置凭证、初始化示例项目、部署、调用和移除。
- 提供包含 Python 运行时示例的 CLI 流程。
快速入门流程
- 1. 安装 Node.js(14+)和 npm。
- 安装并验证 Serverless Devs。
- 通过引导式配置设置凭证。
- 初始化示例项目并进入目录。
- 部署、调用,并可选择移除。
安装 Serverless Devs(npm)
全局安装(需要 sudo):
bash
sudo npm install @serverless-devs/s -g
sudo s -v
免 sudo 替代方案(在受限环境中推荐):
bash
npx -y @serverless-devs/s -v
配置凭证(引导式)
bash
sudo s config add
选择 Alibaba Cloud (alibaba),提供 AccountID、AccessKeyID、AccessKeySecret,并设置别名。
配置凭证(命令行)
使用 CLI 参数通过一条命令(非交互式)配置凭证别名:
bash
s config add -a default --AccessKeyID --AccessKeySecret -f
如果使用环境变量,将其注入命令中(示例):
bash
s config add -a default -kl AccessKeyID,AccessKeySecret -il ${ALIBABACLOUDACCESSKEYID},${ALIBABACLOUDACCESSKEYSECRET} -f
或者使用 Serverless Devs 约定的 JSON 环境变量(示例):
bash
export defaultserverlessdevs_key={\AccountID\:\\,\AccessKeyID\:\\,\AccessKeySecret\:\\}
在 s.yaml 中引用:
yaml
access: defaultserverlessdevs_key
初始化示例(Python)
bash
sudo s init start-fc3-python
cd start-fc3-python
初始化会创建 s.yaml、code/ 和 readme.md;编辑 code/index.py 以实现函数逻辑。
部署、调用和移除
bash
sudo s deploy
sudo s invoke -e test
sudo s remove
自定义域名绑定(避免默认域名强制下载)
注意:FC 默认域名会添加 Content-Disposition: attachment,导致浏览器下载文件。
使用自定义域名可避免此行为。
步骤 1:为域名配置 CNAME
将 DNS CNAME 配置为 FC 公共 CNAME:
id>.id>.fc.aliyuncs.com
示例(杭州地域):
1629965279769872.cn-hangzhou.fc.aliyuncs.com
注意:如果使用根域名(例如 animus.run)且 DNS 提供商不支持根域名的 CNAME,请使用 ALIAS/ANAME 记录,或切换到子域名,例如 www.animus.run。
步骤 2:在 Serverless Devs 中创建自定义域名
选项 A:在 s.yaml 中添加 fc3-domain 资源:
yaml
resources:
newsDomain:
component: fc3-domain
props:
region: cn-hangzhou
domainName: animus.run
protocol: HTTP
routeConfig:
routes:
- functionName: honnold-taipei101-news
qualifier: LATEST
methods:
- GET
- HEAD
path: /*
region 为示例默认值;当最佳地域不明确时,请询问用户。
然后部署:
bash
printf y\n | npx -y @serverless-devs/s deploy
选项 B:使用控制台(高级功能 > 自定义域名)创建并路由自定义域名。
常见错误
- - DomainNameNotResolved:域名未解析到正确的 FC CNAME。
- InvalidICPLicense:中国大陆地域需要与阿里云关联的 ICP 备案。
参考
- - 详细官方步骤请参见 references/installserverlessdevsanddocker.md。
- HTTP 触发器限制及响应头行为(默认域名强制添加 Content-Disposition: attachment)
- https://www.alibabacloud.com/help/en/functioncompute/fc/user-guide/http-triggers-overview
- https://www.alibabacloud.com/help/en/functioncompute/fc/user-guide/configure-custom-domain-names
- - 官方来源列表:references/sources.md
验证
bash
mkdir -p output/aliyun-fc-serverless-devs
echo validation_placeholder > output/aliyun-fc-serverless-devs/validate.txt
通过标准:命令退出码为 0 且生成了 output/aliyun-fc-serverless-devs/validate.txt。
输出与证据
- - 将产物、命令输出和 API 响应摘要保存到 output/aliyun-fc-serverless-devs/ 目录下。
- 在证据文件中包含关键参数(地域/资源 ID/时间范围),以确保可复现性。
前置条件
- - 执行前配置好最小权限的阿里云凭证。
- 优先使用环境变量:ALICLOUDACCESSKEYID、ALICLOUDACCESSKEYSECRET,可选 ALICLOUDREGIONID。
- 如果地域不明确,在执行变更操作前请询问用户。
工作流程
1) 确认用户意图、地域、标识符,以及操作是只读还是变更类型。
2) 首先执行一个最小的只读查询,以验证连接性和权限。
3) 使用明确的参数和限定范围执行目标操作。
4) 验证结果并保存输出/证据文件。