官方sdk文档:https://github.com/aliyun/aliyun-openapi-python-sdk

安装

  1. # Install the core library
  2. pip install aliyun-python-sdk-core
  3. # Install the ECS management library
  4. pip install aliyun-python-sdk-ecs

使用

  1. from aliyunsdkcore.client import AcsClient
  2. from aliyunsdkcore.acs_exception.exceptions import ClientException
  3. from aliyunsdkcore.acs_exception.exceptions import ServerException
  4. from aliyunsdkecs.request.v20140526 import DescribeInstancesRequest
  5. from aliyunsdkecs.request.v20140526 import StopInstanceRequest
  6. client = AcsClient(
  7. "<access-key-id>",
  8. "<access-key-secret>",
  9. "<region-id>"
  10. );
  11. # Initialize a request and set parameters
  12. request = DescribeInstancesRequest.DescribeInstancesRequest()
  13. request.set_PageSize(10)
  14. # Print response
  15. response = client.do_action_with_exception(request)
  16. print response