Category: service
Simple Application Server (SWAS-OPEN 2020-06-01)
Use SWAS-OPEN OpenAPI to manage full SAS resources: instances, disks, snapshots, images, key pairs, firewall, Cloud Assistant, monitoring, tags, and lightweight databases.
Prerequisites
- - Prepare AccessKey with least-privilege RAM user/role.
- Choose correct region and matching endpoint (public/VPC).
ALICLOUD_REGION_ID can be used as default region; if unset choose the most reasonable region, ask user if unclear. - This OpenAPI uses RPC signing; prefer Python SDK or OpenAPI Explorer instead of manual signing.
SDK Priority
1) Python SDK (preferred)
2) OpenAPI Explorer
3) Other SDKs
Python SDK quick query (instance ID / IP / plan)
Virtual environment is recommended (avoid PEP 668 system install restrictions).
CODEBLOCK0
CODEBLOCK1
Python SDK scripts (recommended for inventory and summary)
- - All-region instance inventory (TSV/JSON): INLINECODE1
- Count instances by plan: INLINECODE2
- Count instances by status: INLINECODE3
- Fix SSH key-based access (custom port supported): INLINECODE4
- Get current SSH port of an instance: INLINECODE5
CLI Notes
- -
aliyun CLI may not expose swas-open as product name; prefer Python SDK.
If CLI is mandatory, generate request examples in OpenAPI Explorer first, then migrate to CLI.
Workflow
1) Confirm resource type and region (instance/disk/snapshot/image/firewall/command/database/tag).
2) Identify API group and operation in references/api_overview.md.
3) Choose invocation method (Python SDK / OpenAPI Explorer / other SDK).
4) After mutations, verify state/results with query APIs.
Common Operation Map
- - Instance query/start/stop/reboot:
ListInstances、StartInstance(s)、StopInstance(s)、 INLINECODE12 - Command execution:
RunCommand or CreateCommand + InvokeCommand; use DescribeInvocations/ INLINECODE17 - Firewall:
ListFirewallRules/CreateFirewallRule(s)/ModifyFirewallRule/EnableFirewallRule/ INLINECODE22 - Snapshot/disk/image:
CreateSnapshot、ResetDisk、CreateCustomImage etc.
Cloud Assistant Execution Notes
- - Target instance must be in Running state.
- Cloud Assistant agent must be installed (use
InstallCloudAssistant). - For PowerShell commands, ensure required modules are available on Windows instances.
- After execution, use
DescribeInvocations or DescribeInvocationResult to fetch status and outputs.
See references/command-assistant.md for details.
Clarifying questions (ask when uncertain)
- 1. What is the target region? Is VPC endpoint required?
- What are target instance IDs? Are they currently Running?
- What command/script type/timeout is needed? Linux or Windows?
- Do you need batch execution or scheduled execution?
Output Policy
If you need to save results or responses, write to:
INLINECODE30
Validation
CODEBLOCK2
Pass criteria: command exits 0 and output/alicloud-compute-swas-open/validate.txt is generated.
Output And Evidence
- - Save artifacts, command outputs, and API response summaries under
output/alicloud-compute-swas-open/. - 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.
References
- - API overview and operation groups: INLINECODE36
- Endpoints and integration: INLINECODE37
- Cloud Assistant highlights: INLINECODE38
- Official source list: INLINECODE39
技能名称: alicloud-compute-swas-open
详细描述:
类别: 服务
轻量应用服务器 (SWAS-OPEN 2020-06-01)
使用 SWAS-OPEN OpenAPI 管理全部 SAS 资源:实例、磁盘、快照、镜像、密钥对、防火墙、云助手、监控、标签以及轻量数据库。
前提条件
- - 准备具有最小权限 RAM 用户/角色的 AccessKey。
- 选择正确的区域和匹配的端点(公网/VPC)。ALICLOUDREGIONID 可用作默认区域;若未设置,选择最合理的区域,如不明确则询问用户。
- 此 OpenAPI 使用 RPC 签名;建议使用 Python SDK 或 OpenAPI Explorer,而非手动签名。
SDK 优先级
1) Python SDK(首选)
2) OpenAPI Explorer
3) 其他 SDK
Python SDK 快速查询(实例 ID / IP / 套餐)
建议使用虚拟环境(避免 PEP 668 系统安装限制)。
bash
python3 -m venv .venv
. .venv/bin/activate
python -m pip install alibabacloudswasopen20200601 alibabacloudteaopenapi alibabacloud_credentials
python
import os
from alibabacloudswasopen20200601.client import Client as SwasClient
from alibabacloudswasopen20200601 import models as swas_models
from alibabacloudteaopenapi import models as openapimodels
def createclient(regionid: str) -> SwasClient:
config = openapimodels.Config(
regionid=regionid,
endpoint=fswas.{region_id}.aliyuncs.com,
)
ak = os.getenv(ALICLOUDACCESSKEYID) or os.getenv(ALIBABACLOUDACCESSKEY_ID)
sk = os.getenv(ALICLOUDACCESSKEYSECRET) or os.getenv(ALIBABACLOUDACCESSKEY_SECRET)
if ak and sk:
config.accesskeyid = ak
config.accesskeysecret = sk
return SwasClient(config)
def list_regions():
client = create_client(cn-hangzhou)
resp = client.listregions(swasmodels.ListRegionsRequest())
return [r.region_id for r in resp.body.regions]
def listinstances(regionid: str):
client = createclient(regionid)
resp = client.listinstances(swasmodels.ListInstancesRequest(regionid=regionid))
return resp.body.instances
def main():
for regionid in listregions():
for inst in listinstances(regionid):
ip = getattr(inst, publicipaddress, None) or getattr(inst, inneripaddress, None)
spec = getattr(inst, planname, None) or getattr(inst, planid, None)
print(inst.instanceid, ip or -, spec or -, regionid)
if name == main:
main()
Python SDK 脚本(推荐用于清单和汇总)
- - 全区域实例清单(TSV/JSON):scripts/listinstancesallregions.py
- 按套餐统计实例数:scripts/summaryinstancesbyplan.py
- 按状态统计实例数:scripts/summaryinstancesbystatus.py
- 修复基于 SSH 密钥的访问(支持自定义端口):scripts/fixsshaccess.py
- 获取实例当前 SSH 端口:scripts/getssh_port.py
CLI 说明
- - aliyun CLI 可能不会将 swas-open 作为产品名称暴露;建议使用 Python SDK。
如果必须使用 CLI,请先在 OpenAPI Explorer 中生成请求示例,然后迁移到 CLI。
工作流程
1) 确认资源类型和区域(实例/磁盘/快照/镜像/防火墙/命令/数据库/标签)。
2) 在 references/api_overview.md 中识别 API 组和操作。
3) 选择调用方法(Python SDK / OpenAPI Explorer / 其他 SDK)。
4) 变更后,使用查询 API 验证状态/结果。
常用操作映射
- - 实例查询/启动/停止/重启:ListInstances、StartInstance(s)、StopInstance(s)、RebootInstance(s)
- 命令执行:RunCommand 或 CreateCommand + InvokeCommand;使用 DescribeInvocations/DescribeInvocationResult
- 防火墙:ListFirewallRules/CreateFirewallRule(s)/ModifyFirewallRule/EnableFirewallRule/DisableFirewallRule
- 快照/磁盘/镜像:CreateSnapshot、ResetDisk、CreateCustomImage 等。
云助手执行说明
- - 目标实例必须处于运行中状态。
- 必须安装云助手代理(使用 InstallCloudAssistant)。
- 对于 PowerShell 命令,确保 Windows 实例上有所需模块。
- 执行后,使用 DescribeInvocations 或 DescribeInvocationResult 获取状态和输出。
详见 references/command-assistant.md。
澄清问题(不确定时询问)
- 1. 目标区域是什么?是否需要 VPC 端点?
- 目标实例 ID 是什么?它们当前是否在运行?
- 需要什么命令/脚本类型/超时时间?Linux 还是 Windows?
- 是否需要批量执行或定时执行?
输出策略
如需保存结果或响应,请写入:
output/compute-swas-open/
验证
bash
mkdir -p output/alicloud-compute-swas-open
for f in skills/compute/swas/alicloud-compute-swas-open/scripts/*.py; do
python3 -m py_compile $f
done
echo pycompileok > output/alicloud-compute-swas-open/validate.txt
通过标准:命令退出码为 0 且生成 output/alicloud-compute-swas-open/validate.txt。
输出与证据
- - 将产物、命令输出和 API 响应摘要保存到 output/alicloud-compute-swas-open/ 目录下。
- 在证据文件中包含关键参数(区域/资源 ID/时间范围),以确保可复现性。
前提条件
- - 执行前配置最小权限的阿里云凭证。
- 优先使用环境变量:ALICLOUDACCESSKEYID、ALICLOUDACCESSKEYSECRET,可选 ALICLOUDREGIONID。
- 如果区域不明确,在执行变更操作前询问用户。
工作流程
1) 确认用户意图、区域、标识符以及操作是只读还是变更。
2) 首先执行一次最小的只读查询,以验证连接和权限。
3) 使用明确的参数和有限的范围执行目标操作。
4) 验证结果并保存输出/证据文件。
参考资料
- - API 概览和操作分组:references/api_overview.md
- 端点和集成:references/endpoints.md
- 云助手要点:references/command-assistant.md
- 官方来源列表:references/sources.md