Package: alibabacloud-credentials-py2
English |简体中文Alibaba Cloud Credentials for Python2InstallationInstall with pipPython SDK uses a common package management tool namedpip. If pip is not installed, see thepip user guideto install pip.# Install the alibabacloud_credentials_py2pipinstallalibabacloud_credentials_py2UsageBefore you begin, you need to sign up for an Alibaba Cloud account and retrieve yourCredentials.Credential Typeaccess_keySetup access_key credential through [User Information Management][ak], it have full authority over the account, please keep it safe. Sometimes for security reasons, you cannot hand over a primary account AccessKey with full access to the developer of a project. You may create a sub-account [RAM Sub-account][ram] , grant its [authorization][permissions]，and use the AccessKey of RAM Sub-account.fromalibabacloud_credentials.clientimportClientfromalibabacloud_credentials.modelsimportConfigconfig=Config(type='access_key',# credential typeaccess_key_id='accessKeyId',# AccessKeyIdaccess_key_secret='accessKeySecret',# AccessKeySecret)cred=Client(config)access_key_id=cred.get_access_key_id()access_key_secret=cred.get_access_key_secret()cred_type=cred.get_type()stsCreate a temporary security credential by applying Temporary Security Credentials (TSC) through the Security Token Service (STS).fromalibabacloud_credentials.clientimportClientfromalibabacloud_credentials.modelsimportConfigconfig=Config(type='sts',# credential typeaccess_key_id='accessKeyId',# AccessKeyIdaccess_key_secret='accessKeySecret',# AccessKeySecretsecurity_token='securityToken'# STS Token)cred=Client(config)access_key_id=cred.get_access_key_id()access_key_secret=cred.get_access_key_secret()security_token=cred.get_security_token()cred_type=cred.get_type()ram_role_arnBy specifying [RAM Role][RAM Role], the credential will be able to automatically request maintenance of STS Token. If you want to limit the permissions([How to make a policy][policy]) of STS Token, you can assign value forPolicy.fromalibabacloud_credentials.clientimportClientfromalibabacloud_credentials.modelsimportConfigconfig=Config(type='ram_role_arn',# credential typeaccess_key_id='accessKeyId',# AccessKeyIdaccess_key_secret='accessKeySecret',# AccessKeySecretsecurity_token='securityToken',# STS Tokenrole_arn='roleArn',# Format: acs:ram::USER_ID:role/ROLE_NAMErole_session_name='roleSessionName',# Role Session Namepolicy='policy',# Not required, limit the permissions of STS Tokenrole_session_expiration=3600# Not required, limit the Valid time of STS Token)cred=Client(config)access_key_id=cred.get_access_key_id()access_key_secret=cred.get_access_key_secret()security_token=cred.get_security_token()cred_type=cred.get_type()OIDC Role ARNBy specifying [OIDC Role][OIDC Role], the credential will be able to automatically request maintenance of STS Token. If you want to limit the permissions([How to make a policy][policy]) of STS Token, you can assign value forPolicy.fromalibabacloud_credentials.clientimportClientfromalibabacloud_credentials.modelsimportConfigconfig=Config(type='oidc_role_arn',# credential typeaccess_key_id='accessKeyId',# AccessKeyIdaccess_key_secret='accessKeySecret',# AccessKeySecretsecurity_token='securityToken',# STS Tokenrole_arn='roleArn',# Format: acs:ram::USER_ID:role/ROLE_NAMEoidc_provider_arn='oidcProviderArn',# Format: acs:ram::USER_Id:oidc-provider/OIDC Providersoidc_token_file_path='/Users/xxx/xxx',# oidc_token_file_path can be replaced by setting environment variable: ALIBABA_CLOUD_OIDC_TOKEN_FILErole_session_name='roleSessionName',# Role Session Namepolicy='policy',# Not required, limit the permissions of STS Tokenrole_session_expiration=3600# Not required, limit the Valid time of STS Token)cred=Client(config)access_key_id=cred.get_access_key_id()access_key_secret=cred.get_access_key_secret()security_token=cred.get_security_token()cred_type=cred.get_type()ecs_ram_roleBy specifying the role name, the credential will be able to automatically request maintenance of STS Token.fromalibabacloud_credentials.clientimportClientfromalibabacloud_credentials.modelsimportConfigconfig=Config(type='ecs_ram_role',# credential typerole_name='roleName'# `roleName` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests.)cred=Client(config)access_key_id=cred.get_access_key_id()access_key_secret=cred.get_access_key_secret()security_token=cred.get_security_token()cred_type=cred.get_type()rsa_key_pairBy specifying the public key ID and the private key file, the credential will be able to automatically request maintenance of the AccessKey before sending the request. Only Japan station is supported.fromalibabacloud_credentials.clientimportClientfromalibabacloud_credentials.modelsimportConfigconfig=Config(type='rsa_key_pair',# credential typeprivate_key_file='privateKeyFile',# The file path to store the PrivateKeypublic_key_id='publicKeyId'# PublicKeyId of your account)cred=Client(config)access_key_id=cred.get_access_key_id()access_key_secret=cred.get_access_key_secret()security_token=cred.get_security_token()cred_type=cred.get_type()bearerIf credential is required by the Cloud Call Centre (CCC), please apply for Bearer Token maintenance by yourself.fromalibabacloud_credentials.clientimportClientfromalibabacloud_credentials.modelsimportConfigconfig=Config(type='bearer',# credential typebearer_token='bearerToken',# BearerToken)cred=Client(config)access_key_id=cred.get_access_key_id()access_key_secret=cred.get_access_key_secret()security_token=cred.get_security_token()cred_type=cred.get_type()Use the default credential provider chainfromalibabacloud_credentials.clientimportClientasCredClientfromalibabacloud_ocr20191230.clientimportClientasOcrClientfromalibabacloud_ocr20191230.modelsimportGetAsyncJobResultRequestfromalibabacloud_tea_rpc.modelsimportConfigfromalibabacloud_tea_util.modelsimportRuntimeOptionscred=CredClient()config=Config(credential=cred)client=OcrClient(config)request=GetAsyncJobResultRequest(job_id='<job_id>')runtime_options=RuntimeOptions()response=client.get_async_job_result(request,runtime_options)The default credential provider chain looks for available credentials, with following order:1.Environment CredentialsLook for environment credentials in environment variable. If theALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETenvironment variables are defined and are not empty, the program will use them to create default credentials.2.Credentials FileIf there is~/.alibabacloud/credentials default file (Windows shows C:\Users\USER_NAME\.alibabacloud\credentials), the program automatically creates credentials with the specified type and name. The default file is not necessarily exist, but a parse error will throw an exception. The name of configuration item is lowercase.This configuration file can be shared between different projects and between different tools. Because it is outside of the project and will not be accidentally committed to the version control. The path to the default file can be modified by defining theALIBABA_CLOUD_CREDENTIALS_FILEenvironment variable. If not configured, use the default configurationdefault. You can also set the environment variablesALIBABA_CLOUD_PROFILEto use the configuration.[default]                          # default settingenable=true# Enable，Enabled by default if this option is not presenttype=access_key# Certification type: access_keyaccess_key_id=foo# Keyaccess_key_secret=bar# Secret[client1]                          # configuration that is named as `client1`type=ecs_ram_role# Certification type: ecs_ram_rolerole_name=EcsRamRoleTest# Role Name[client2]                          # configuration that is named as `client2`enable=false# Disabletype=ram_role_arn# Certification type: ram_role_arnregion_id=cn-testpolicy=test# optional Specify permissionsaccess_key_id=fooaccess_key_secret=barrole_arn=role_arnrole_session_name=session_name# optional[client3]                          # configuration that is named as `client3`type=rsa_key_pair# Certification type: rsa_key_pairpublic_key_id=publicKeyId# Public Key IDprivate_key_file=/your/pk.pem# Private Key file[client3]                          # configuration that is named as `client3`type=rsa_key_pair# Certification type: rsa_key_pairpublic_key_id=publicKeyId# Public Key IDprivate_key_file=/your/pk.pem# Private Key file[client4]                          # configuration that is named as `client4`enable=false# Disabletype=oidc_role_arn# Certification type: oidc_role_arnregion_id=cn-testpolicy=test# optional Specify permissionsaccess_key_id=foo# optionalaccess_key_secret=bar# optionalrole_arn=role_arnoidc_provider_arn=oidc_provider_arnoidc_token_file_path=/xxx/xxx# can be replaced by setting environment variable: ALIBABA_CLOUD_OIDC_TOKEN_FILErole_session_name=session_name# optional3.Instance RAM RoleIf the environment variableALIBABA_CLOUD_ECS_METADATAis defined and not empty, the program will take the value of the environment variable as the role name and requesthttp://100.100.100.200/latest/meta-data/ram/security-credentials/to get the temporary Security credentials.IssuesOpening an Issue, Issues not conforming to the guidelines may be closed immediately.ChangelogDetailed changes for each release are documented in therelease notes.ReferencesLatest ReleaseLicenseApache-2.0Copyright (c) 2009-present, Alibaba Cloud All rights reserved.