{"id":7921,"library":"aliyun-python-sdk-ecs","title":"Alibaba Cloud ECS SDK (V1.0)","description":"aliyun-python-sdk-ecs is the Elastic Compute Service (ECS) module of the Alibaba Cloud Python SDK V1.0. This SDK provides an interface to interact with Alibaba Cloud ECS resources. While actively maintained with frequent updates, the V1.0 SDK is in a basic security maintenance phase, and Alibaba Cloud officially recommends migrating to the V2.0 SDK (`alibabacloud-python-sdk`) for new development and improved features.","status":"maintenance","version":"4.24.82","language":"en","source_language":"en","source_url":"https://github.com/aliyun/aliyun-openapi-python-sdk/tree/master/aliyun-python-sdk-ecs","tags":["aliyun","alibaba cloud","ecs","cloud computing","sdk"],"install":[{"cmd":"pip install aliyun-python-sdk-core aliyun-python-sdk-ecs","lang":"bash","label":"Install core and ECS SDK"}],"dependencies":[{"reason":"This is the core library required for all V1.0 Alibaba Cloud SDKs.","package":"aliyun-python-sdk-core","optional":false}],"imports":[{"symbol":"AcsClient","correct":"from aliyunsdkcore.client import AcsClient"},{"symbol":"DescribeInstancesRequest","correct":"from aliyunsdkecs.request.v20140526.DescribeInstancesRequest import DescribeInstancesRequest"},{"note":"Requests are versioned, typically under a 'vYYYYMMDD' path. Omitting the version will cause ModuleNotFoundError.","wrong":"from aliyunsdkecs.request.RunInstancesRequest import RunInstancesRequest","symbol":"RunInstancesRequest","correct":"from aliyunsdkecs.request.v20140526.RunInstancesRequest import RunInstancesRequest"}],"quickstart":{"code":"import os\nfrom aliyunsdkcore.client import AcsClient\nfrom aliyunsdkecs.request.v20140526.DescribeInstancesRequest import DescribeInstancesRequest\n\n# Configure credentials and region using environment variables\naccess_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY_ID')\naccess_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'YOUR_ACCESS_KEY_SECRET')\nregion_id = os.environ.get('ALIBABA_CLOUD_REGION_ID', 'cn-hangzhou')\n\nif not access_key_id or not access_key_secret:\n    raise ValueError(\"Alibaba Cloud Access Key ID and Secret must be set in environment variables or hardcoded for testing.\")\n\ntry:\n    # Initialize the AcsClient\n    client = AcsClient(access_key_id, access_key_secret, region_id)\n\n    # Create a request object for DescribeInstances\n    request = DescribeInstancesRequest()\n    request.set_PageSize(10)\n\n    # Send the request and get the response\n    response = client.do_action_with_exception(request)\n\n    # Process the response (response is a byte string, decode it)\n    import json\n    response_data = json.loads(response.decode('utf-8'))\n\n    print(f\"Successfully queried instances in region {region_id}:\")\n    for instance in response_data.get('Instances', {}).get('Instance', []):\n        print(f\"  Instance ID: {instance['InstanceId']}, Status: {instance['Status']}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the V1.0 ECS client using environment variables for credentials and fetch a list of ECS instances. It uses `DescribeInstancesRequest` as a common API call. Remember to replace placeholder values or set environment variables."},"warnings":[{"fix":"Migrate to `alibabacloud-python-sdk`. The import patterns and client initialization differ significantly. Refer to the official Alibaba Cloud Python SDK 2.0 documentation for migration guides.","message":"The Alibaba Cloud Python SDK V1.0, which includes `aliyun-python-sdk-ecs`, is officially deprecated and in a basic security maintenance phase. Users are strongly recommended to migrate to the V2.0 SDK (`alibabacloud-python-sdk`) for new projects and actively maintained features.","severity":"breaking","affected_versions":"<=4.24.82"},{"fix":"Ensure your Python environment is version 3.7 or newer. Upgrade Python if necessary, or use a virtual environment with a compatible Python version.","message":"As of `aliyun-python-sdk-core` version 2.16.0, the minimum supported Python version is 3.7. Attempting to use this SDK with older Python versions (e.g., Python 2.7, 3.6) will lead to compatibility issues or installation failures.","severity":"gotcha","affected_versions":">=2.16.0 of aliyun-python-sdk-core"},{"fix":"Implement logic to poll the instance status using `DescribeInstancesRequest` or `DescribeInstanceAttributeRequest` and wait for the desired state before proceeding with dependent operations. The V2.0 SDK offers `instance.wait_until(ECSInstanceResource.STATUS_RUNNING)` for this purpose.","message":"Many ECS operations (e.g., StartInstance, StopInstance, ReleaseInstance) are asynchronous and require the ECS instance to be in a specific state before the operation can succeed. Failing to check the instance status can lead to API errors.","severity":"gotcha","affected_versions":"All V1.0 versions"},{"fix":"Explicitly set `request.set_InternetChargeType('PayByBandwidth')` or `'PayByTraffic'` when calling `AllocateEipAddressRequest` to avoid this known API issue.","message":"When allocating an EIP (`AllocateEipAddressRequest`), you might encounter an API error if the `InternetChargeType` parameter is not explicitly set, even though it might seem optional in some contexts.","severity":"gotcha","affected_versions":"Specific versions related to ECS API, observed around 2019"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the core SDK: `pip install aliyun-python-sdk-core`.","cause":"The core SDK (`aliyun-python-sdk-core`) is a mandatory dependency and has not been installed.","error":"ModuleNotFoundError: No module named 'aliyunsdkcore'"},{"fix":"Upgrade `pip` and `setuptools`: `pip install --upgrade pip setuptools`. Ensure your Python version meets the SDK requirements (Python 3.7+ for recent `aliyunsdkcore`).","cause":"This often indicates an outdated `pip` or Python version, or missing build-time dependencies required for package installation.","error":"Command 'python setup.py egg_info' failed with error code 1 in /path/to/package"},{"fix":"Before performing state-changing operations, query the instance's current status (e.g., using `DescribeInstancesRequest`) and wait for it to reach the correct state. For example, an instance must be 'Stopped' to be 'Started', and 'Running' to be 'Stopped'.","cause":"You are attempting to perform an action (e.g., start, stop, release an instance) on an ECS instance that is not in the required state for that operation.","error":"The current status of the resource does not support this operation."},{"fix":"Verify the `region_id` string format (e.g., 'cn-hangzhou'). Ensure `aliyunsdkcore` is updated to the latest version: `pip install --upgrade aliyun-python-sdk-core`.","cause":"This error typically means the region ID provided during `AcsClient` initialization is invalid or the SDK version is too old to recognize the endpoint for the specified region.","error":"SDK.HttpError: The endpoint is not found."}]}