Manage credentials for Tencent Cloud SDK
masterThe Python SDK supports several methods for managing secretId and secretKey credentials:
1. Environment Variables
Reads TENCENTCLOUD_SECRET_ID and TENCENTCLOUD_SECRET_KEY from your environment.
2. Configuration Files
Uses an .ini formatted file at the following locations:
- Windows:
c:\Users\NAME\.tencentcloud\credentials - Linux:
~/.tencentcloud/credentialsor/etc/tencentcloud/credentials
File Format:
[default]
secret_id = xxxxx
secret_key = xxxxx3. Role Assumption (STS)
Used to obtain temporary credentials by assuming a pre-created role in the Tencent Cloud console.
4. Instance Role (CVM)
Automatically fetches and refreshes temporary credentials from the instance metadata service when a role is bound to the instance.
5. Credential Provider Chain
The SDK provides a default chain that attempts to retrieve credentials in this order: Environment Variables -> Configuration Files -> Instance Role -> TKE OIDC Credentials.
from tencentcloud.common import credential
# 1. Environment Variables
cred = credential.EnvironmentVariableCredential().get_credential()
# 2. Configuration Files
cred = credential.ProfileCredential().get_credential()
# 3. Role Assumption (STS)
cred = credential.STSAssumeRoleCredential("SecretId", "SecretKey", "RoleArn", "RoleSessionName")
# 4. Instance Role (CVM)
cred = credential.CVMRoleCredential().get_credential()
# 5. Default Provider Chain
cred = credential.DefaultCredentialProvider().get_credential()
# 6. TKE OIDC Credentials
cred = credential.DefaultTkeOIDCRoleArnProvider().get_credential()