全部产品
阿里云办公

示例

更新时间:2018-01-30 09:45:42

  1. #!/usr/bin/env python
  2. #coding=utf-8
  3. from aliyunsdkcore import client
  4. from aliyunsdkcore.profile import region_provider
  5. from aliyunsdksts.request.v20150401 import AssumeRoleRequest
  6. # 构建一个 Aliyun Client, 用于发起请求
  7. # 构建Aliyun Client时需要设置AccessKeyId和AccessKeySevcret
  8. REGIONID = 'cn-shanghai'
  9. ENDPOINT = 'sts.cn-shanghai.aliyuncs.com'
  10. # 配置要访问的STS Endpoint
  11. region_provider.add_endpoint('Sts', REGIONID, ENDPOINT)
  12. # 初始化Client
  13. clt = client.AcsClient('<access-key-id>','<access-key-secret>', REGIONID)
  14. # 构造"AssumeRole"请求
  15. request = AssumeRoleRequest.AssumeRoleRequest()
  16. # 指定角色
  17. request.set_RoleArn('<role-arn>')
  18. # 设置会话名称,审计服务使用此名称区分调用者
  19. request.set_RoleSessionName('<role-session-name>')
  20. # 发起请求,并得到response
  21. response = clt.do_action_with_exception(request)
  22. print response