This topic provides the download URLs of the Python SDK packages that are required for you to use STS. This topic also describes how to use the STS SDK for Python.
You can download the SDK packages from the following links:
Use the STS SDK for Python
#!/usr/bin/env python #coding=utf-8 from aliyunsdkcore import client from aliyunsdkcore.profile import region_provider from aliyunsdksts.request.v20150401 import AssumeRoleRequest # Construct an Alibaba Cloud client. The client will be used to send a request. # When you construct the client, set the AccessKey ID and AccessKey secret. REGIONID = 'cn-shanghai' ENDPOINT = 'sts.cn-shanghai.aliyuncs.com' # Specify the STS endpoint that you want to access. region_provider.add_endpoint('Sts', REGIONID, ENDPOINT) # Initialize the client. clt = client.AcsClient('<access-key-id>','<access-key-secret>', REGIONID) # Construct an AssumeRole request. request = AssumeRoleRequest.AssumeRoleRequest() # Specify the Alibaba Cloud Resource Name (ARN) of the RAM role. request.set_RoleArn('<role-arn>') # Specify a role session name, which is used to identify the RAM user who assumes the RAM role. request.set_RoleSessionName('<role-session-name>') # Specify a policy to grant the returned STS token fewer permissions than those granted to the RAM role. request.set_Policy('<policy>') # Issue the request and obtain a response. response = clt.do_action_with_exception(request) print response