Obtains the access credential for cloud services.
CredentialProviderChain().get_credential()
This operation returns the temporary credential for accessing a cloud service. The
credential is updated every 15 minutes. Therefore, you can call this operation to
obtain the updated credential when you want to access a cloud service. The format
of the credential is as follows:
Parameter | Type | Description |
---|---|---|
accessKeyId | String | The AccessKey ID. The AccessKey pair consists of an AccessKey ID and an AccessKey secret. You can use the AccessKey pair to authenticate API requests that you make to Alibaba Cloud. |
accessKeySecret | String | The AccessKey secret. |
securityToken | String | The security token. |
Sample requests
This example describes how to use the CredentialProviderChain().resolvePromise() method. The sample code is as follows:
Note The sample code depends on the third-party library oss2. Download the putOssFilePy-code.zip file to see the complete code.
# -*- coding: utf-8 -*-
import oss2
import lecoresdk
def handler(event, context):
cred = lecoresdk.CredentialProviderChain().get_credential()
auth = oss2.StsAuth(cred['accessKeyId'], cred['accessKeySecret'], cred['securityToken'])
bucket = oss2.Bucket(auth, 'http://oss-cn-shanghai.aliyuncs.com', 'le-fc-bucket')
bucket.put_object('fileFromEdgePy.txt', 'Content of object')
print("-- Put fileFromEdgePy.txt to OSS.")
return 'OK'