CredentialProviderChain
Updated at:
Copy as MD
You can call this API to obtain access credentials for an Alibaba Cloud service.
CredentialProviderChain().get_credential()
This API returns temporary credentials for an Alibaba Cloud service. The credentials are automatically updated every 15 minutes by default. Call this API to retrieve the latest credentials before you access the service. The credential format includes the following parameters:
| Parameter | Type | Description |
| accessKeyId | String | The AccessKey ID. An AccessKey pair consists of an AccessKey ID and an AccessKey secret. It is used for identity authentication in API requests to Alibaba Cloud services. |
| accessKeySecret | String | The AccessKey secret. |
| securityToken | String | The security token. |
Example
The following example shows how to use CredentialProviderChain().get_credential() to access the OSS service.
Note The sample code depends on the oss2 third-party library. Download the complete code package putOssFilePy-code.zip to view the full 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'Is this page helpful?