BcmClient
Create a New BcmClient
Being the client of the BCM service, BcmClient provides a series of methods for developers to interact with the BCM service.
Access to BCM via AK/SK
1.Before creation of BcmClient, first create a configuration file to configure BcmClient, and in the following, configuration file is named as bcm_sample_conf.py
, with specific configuration information as follows:
#!/usr/bin/env python
#coding=utf-8
# Import Python standard log module
import logging
# Import BCE configuration management module and security authentication module from Python SDK
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.auth.bce_credentials import BceCredentials
# Set Host, Access Key ID and Secret Access Key of BcmClient
bcm_host = "bcm.bj.baidubce.com"
access_key_id = "AK"
secret_access_key = "SK"
# Set handle and log level of log file
logger = logging.getLogger('baidubce.http.bce_http_client')
fh = logging.FileHandler("sample.log")
fh.setLevel(logging.DEBUG)
# Set output sequence, structure and contents of log file.
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.setLevel(logging.DEBUG)
logger.addHandler(fh)
#Create BceClientConfiguration
config = BceClientConfiguration(credentials=BceCredentials(access_key_id, secret_access_key), endpoint = bcm_host)
Note: For the log file, Logging has the following levels: DEBUG, INFO, WARNING, ERROR, CRITICAL.
Of the codes mentioned above, ACCESS_KEY_ID corresponds to the “Access Key ID” in the console, and secret_access_key corresponds to “Access Key Secret” in the console. Please refer to Manage ACCESSKEY for access mode.
For the method above, you need to specify service domain name of BCM by themselves, which can be specified by assigning a value to bcm_host
variable.
2.After completing the configuration above, create a BcmClient by reference to the following codes.
#Import BcmClient configuration documentation
import bcm_sample_conf
#Import BCM-related modules
from baidubce import exception
from baidubce.services import bcm
from baidubce.services.bcm.bcm_client import BcmClient
#Create a new BcmClient
bcm_client = BcmClient(bcm_sample_conf.config)