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).
ALIBABACLOUD_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
- Python SDK (preferred)
- OpenAPI Explorer
- Other SDKs
Python SDK quick query (instance ID / IP / plan)
Virtual environment is recommended (avoid PEP 668 system install restrictions).
python3 -m venv .venv
. .venv/bin/activate
python -m pip install alibabacloud_swas_open20200601 alibabacloud_tea_openapi alibabacloud_credentials
import os
from alibabacloud_swas_open20200601.client import Client as SwasClient
from alibabacloud_swas_open20200601 import models as swas_models
from alibabacloud_tea_openapi import models as open_api_models
def create_client(region_id: str) -> SwasClient:
config = open_api_models.Config(
region_id=region_id,
endpoint=f"swas.{region_id}.aliyuncs.com",
)
ak = (
os.getenv("ALIBABACLOUD_ACCESS_KEY_ID")
or os.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
or os.getenv("ALICLOUD_ACCESS_KEY_ID")
)
sk = (
os.getenv("ALIBABACLOUD_ACCESS_KEY_SECRET")
or os.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
or os.getenv("ALICLOUD_ACCESS_KEY_SECRET")
)
if ak and sk:
config.access_key_id = ak
config.access_key_secret = sk
return SwasClient(config)
def list_regions():
client = create_client("cn-hangzhou")
resp = client.list_regions(swas_models.ListRegionsRequest())
return [r.region_id for r in resp.body.regions]
def list_instances(region_id: str):
client = create_client(region_id)
resp = client.list_instances(swas_models.ListInstancesRequest(region_id=region_id))
return resp.body.instances
def main():
for region_id in list_regions():
for inst in list_instances(region_id):
ip = getattr(inst, "public_ip_address", None) or getattr(inst, "inner_ip_address", None)
spec = getattr(inst, "plan_name", None) or getattr(inst, "plan_id", None)
print(inst.instance_id, ip or "-", spec or "-", region_id)
if __name__ == "__main__":
main()
Python SDK scripts (recommended for inventory and summary)
- All-region instance inventory (TSV/JSON):
scripts/list_instances_all_regions.py
- Count instances by plan:
scripts/summary_instances_by_plan.py
- Count instances by status:
scripts/summary_instances_by_status.py
- Fix SSH key-based access (custom port supported):
scripts/fix_ssh_access.py
- Get current SSH port of an instance:
scripts/get_ssh_port.py
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
- Confirm resource type and region (instance/disk/snapshot/image/firewall/command/database/tag).
- Identify API group and operation in
references/api_overview.md.
- Choose invocation method (Python SDK / OpenAPI Explorer / other SDK).
- After mutations, verify state/results with query APIs.
Common Operation Map
- Instance query/start/stop/reboot:
ListInstances、StartInstance(s)、StopInstance(s)、RebootInstance(s)
- Command execution:
RunCommand or CreateCommand + InvokeCommand; use DescribeInvocations/DescribeInvocationResult
- Firewall:
ListFirewallRules/CreateFirewallRule(s)/ModifyFirewallRule/EnableFirewallRule/DisableFirewallRule
- 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)
- 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:
output/compute-swas-open/
Validation
mkdir -p output/aliyun-swas-manage
for f in skills/compute/swas/aliyun-swas-manage/scripts/*.py; do
python3 -m py_compile "$f"
done
echo "py_compile_ok" > output/aliyun-swas-manage/validate.txt
Pass criteria: command exits 0 and output/aliyun-swas-manage/validate.txt is generated.
Output And Evidence
- Save artifacts, command outputs, and API response summaries under
output/aliyun-swas-manage/.
- 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:
ALIBABACLOUD_ACCESS_KEY_ID, ALIBABACLOUD_ACCESS_KEY_SECRET, optional ALIBABACLOUD_REGION_ID.
- If region is unclear, ask the user before running mutating operations.
Workflow
- Confirm user intent, region, identifiers, and whether the operation is read-only or mutating.
- Run one minimal read-only query first to verify connectivity and permissions.
- Execute the target operation with explicit parameters and bounded scope.
- Verify results and save output/evidence files.
References
- API overview and operation groups:
references/api_overview.md
- Endpoints and integration:
references/endpoints.md
- Cloud Assistant highlights:
references/command-assistant.md
- Official source list:
references/sources.md
1---2name: aliyun-swas-manage3description: Use when managing Alibaba Cloud Simple Application Server (SWAS OpenAPI 2020-06-01) resources end-to-end, including querying instances, starting/stopping/rebooting, executing commands (cloud assistant), managing disks/snapshots/images, firewall rules/templates, key pairs, tags, monitoring, and lightweight database operations.4---56Category: service78# Simple Application Server (SWAS-OPEN 2020-06-01)910Use SWAS-OPEN OpenAPI to manage full SAS resources: instances, disks, snapshots, images, key pairs, firewall, Cloud Assistant, monitoring, tags, and lightweight databases.1112## Prerequisites1314- Prepare AccessKey with least-privilege RAM user/role.15- Choose correct region and matching endpoint (public/VPC).`ALIBABACLOUD_REGION_ID` can be used as default region; if unset choose the most reasonable region, ask user if unclear.16- This OpenAPI uses RPC signing; prefer Python SDK or OpenAPI Explorer instead of manual signing.1718## SDK Priority19201) Python SDK (preferred)212) OpenAPI Explorer223) Other SDKs2324### Python SDK quick query (instance ID / IP / plan)2526Virtual environment is recommended (avoid PEP 668 system install restrictions).2728```bash29python3 -m venv .venv30. .venv/bin/activate31python -m pip install alibabacloud_swas_open20200601 alibabacloud_tea_openapi alibabacloud_credentials32```3334```python35import os36from alibabacloud_swas_open20200601.client import Client as SwasClient37from alibabacloud_swas_open20200601 import models as swas_models38from alibabacloud_tea_openapi import models as open_api_models394041def create_client(region_id: str) -> SwasClient:42 config = open_api_models.Config(43 region_id=region_id,44 endpoint=f"swas.{region_id}.aliyuncs.com",45 )46 ak = (47 os.getenv("ALIBABACLOUD_ACCESS_KEY_ID")48 or os.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")49 or os.getenv("ALICLOUD_ACCESS_KEY_ID")50 )51 sk = (52 os.getenv("ALIBABACLOUD_ACCESS_KEY_SECRET")53 or os.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")54 or os.getenv("ALICLOUD_ACCESS_KEY_SECRET")55 )56 if ak and sk:57 config.access_key_id = ak58 config.access_key_secret = sk59 return SwasClient(config)606162def list_regions():63 client = create_client("cn-hangzhou")64 resp = client.list_regions(swas_models.ListRegionsRequest())65 return [r.region_id for r in resp.body.regions]666768def list_instances(region_id: str):69 client = create_client(region_id)70 resp = client.list_instances(swas_models.ListInstancesRequest(region_id=region_id))71 return resp.body.instances727374def main():75 for region_id in list_regions():76 for inst in list_instances(region_id):77 ip = getattr(inst, "public_ip_address", None) or getattr(inst, "inner_ip_address", None)78 spec = getattr(inst, "plan_name", None) or getattr(inst, "plan_id", None)79 print(inst.instance_id, ip or "-", spec or "-", region_id)808182if __name__ == "__main__":83 main()84```8586### Python SDK scripts (recommended for inventory and summary)8788- All-region instance inventory (TSV/JSON):`scripts/list_instances_all_regions.py`89- Count instances by plan:`scripts/summary_instances_by_plan.py`90- Count instances by status:`scripts/summary_instances_by_status.py`91- Fix SSH key-based access (custom port supported):`scripts/fix_ssh_access.py`92- Get current SSH port of an instance:`scripts/get_ssh_port.py`9394## CLI Notes9596- `aliyun` CLI may not expose `swas-open` as product name; prefer Python SDK.97 If CLI is mandatory, generate request examples in OpenAPI Explorer first, then migrate to CLI.9899## Workflow1001011) Confirm resource type and region (instance/disk/snapshot/image/firewall/command/database/tag). 1022) Identify API group and operation in `references/api_overview.md`. 1033) Choose invocation method (Python SDK / OpenAPI Explorer / other SDK). 1044) After mutations, verify state/results with query APIs. 105106## Common Operation Map107108- Instance query/start/stop/reboot:`ListInstances`、`StartInstance(s)`、`StopInstance(s)`、`RebootInstance(s)` 109- Command execution:`RunCommand` or `CreateCommand` + `InvokeCommand`; use `DescribeInvocations`/`DescribeInvocationResult` 110- Firewall:`ListFirewallRules`/`CreateFirewallRule(s)`/`ModifyFirewallRule`/`EnableFirewallRule`/`DisableFirewallRule` 111- Snapshot/disk/image:`CreateSnapshot`、`ResetDisk`、`CreateCustomImage` etc. 112113## Cloud Assistant Execution Notes114115- Target instance must be in Running state.116- Cloud Assistant agent must be installed (use `InstallCloudAssistant`).117- For PowerShell commands, ensure required modules are available on Windows instances.118- After execution, use `DescribeInvocations` or `DescribeInvocationResult` to fetch status and outputs.119120See `references/command-assistant.md` for details.121122## Clarifying questions (ask when uncertain)1231241. What is the target region? Is VPC endpoint required?1252. What are target instance IDs? Are they currently Running?1263. What command/script type/timeout is needed? Linux or Windows?1274. Do you need batch execution or scheduled execution?128129## Output Policy130131If you need to save results or responses, write to:132`output/compute-swas-open/`133134## Validation135136```bash137mkdir -p output/aliyun-swas-manage138for f in skills/compute/swas/aliyun-swas-manage/scripts/*.py; do139 python3 -m py_compile "$f"140done141echo "py_compile_ok" > output/aliyun-swas-manage/validate.txt142```143144Pass criteria: command exits 0 and `output/aliyun-swas-manage/validate.txt` is generated.145146## Output And Evidence147148- Save artifacts, command outputs, and API response summaries under `output/aliyun-swas-manage/`.149- Include key parameters (region/resource id/time range) in evidence files for reproducibility.150151## Prerequisites152153- Configure least-privilege Alibaba Cloud credentials before execution.154- Prefer environment variables: `ALIBABACLOUD_ACCESS_KEY_ID`, `ALIBABACLOUD_ACCESS_KEY_SECRET`, optional `ALIBABACLOUD_REGION_ID`.155- If region is unclear, ask the user before running mutating operations.156157## Workflow1581591) Confirm user intent, region, identifiers, and whether the operation is read-only or mutating.1602) Run one minimal read-only query first to verify connectivity and permissions.1613) Execute the target operation with explicit parameters and bounded scope.1624) Verify results and save output/evidence files.163164## References165166- API overview and operation groups:`references/api_overview.md`167- Endpoints and integration:`references/endpoints.md`168- Cloud Assistant highlights:`references/command-assistant.md`169- Official source list:`references/sources.md`