Alibaba Cloud ECS SDK (20140526)

raw JSON →
7.7.4 verified Mon Apr 27 auth: no python

Official Alibaba Cloud Python SDK for Elastic Compute Service (ECS) API version 2014-05-26. Current version is 7.7.4, actively maintained with monthly releases aligning with Alibaba Cloud API updates.

pip install alibabacloud-ecs20140526
error ModuleNotFoundError: No module named 'alibabacloud_ecs20140526'
cause Package not installed or wrong Python environment.
fix
Run 'pip install alibabacloud-ecs20140526' (note underscores become hyphens in pip).
error AttributeError: module 'alibabacloud_ecs20140526' has no attribute 'Client'
cause Importing Client from top-level package instead of submodule.
fix
Use 'from alibabacloud_ecs20140526.client import Client'.
error UnsupportedOperation: This API version is not supported in this SDK.
cause Using old aliyunsdkcore (v2) with new alibabacloud SDK; incompatible.
fix
Uninstall aliyunsdkcore and use alibabacloud-tea and alibabacloud-credentials.
breaking In v7.x, the SDK switched to Tea-based models and client. Old v2.x code using 'from aliyunsdkecs.request.v20140526' is deprecated and will not work with this package.
fix Use 'from alibabacloud_ecs20140526.client import Client' and Tea models.
deprecated Direct instantiation of request models without namespace was deprecated. Models must be imported from .models submodule.
fix Use 'from alibabacloud_ecs20140526.models import CreateInstanceRequest'.
gotcha Endpoint must be explicitly provided; there is no automatic detection. Using the wrong region endpoint will cause timeout or auth errors.
fix Set config.endpoint to the correct regional endpoint, e.g., 'ecs-cn-hangzhou.aliyuncs.com'.
gotcha Page size for DescribeInstances defaults to 10; large accounts may miss instances if not using pagination.
fix Set request.max_results to a higher value (max 100) and handle NextToken in loop.

Initialize client with credentials from environment variables, describe instances.

import os
from alibabacloud_ecs20140526.client import Client
from alibabacloud_ecs20140526 import models
from alibabacloud_tea_openapi import models as open_api_models

config = open_api_models.Config(
    access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', ''),
    access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', ''),
    endpoint='ecs-cn-hangzhou.aliyuncs.com'
)
client = Client(config)
req = models.DescribeInstancesRequest()
resp = client.describe_instances(req)
print(resp.body.instances.instance)