我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用boto3.set_stream_logger()。
def __init__(self, region, retries=100): boto3.set_stream_logger('boto3', logging.INFO) self.session = boto3.Session() self.region = region self.retries = retries self._ec2_client = None self._ec2_resource = None self._cloudwatch_client = None self._iam_client = None
def session(self): '''Get a low-level session object or create one if needed''' if not self._session: if self.config.debug_mode: boto3.set_stream_logger(level=log.DEBUG) self._session = boto3.session.Session( region_name=self.region_name, **self.session_cfg) return self._session
def TestMain(cfg): # boto3.set_stream_logger(name='botocore') # os.environ["HTTP_PROXY"] = "http://localhost:8080" # os.environ["HTTPS_PROXY"] = "https://localhost:8999" sess = boto3.session.Session( aws_access_key_id = cfg['access_key_id'], aws_secret_access_key = cfg['access_key'], region_name = cfg['region'] ) s3 = sess.resource('s3') print '\n--- List Buckets ---' for bucket in s3.buckets.all(): print bucket.name bkt = s3.Bucket('fred4') # print '\n--- Key exists ---' # print bkt.get_key('zuxisaki') # i dont think this works print '\n--- List objects in bucket fred4 ---' # len(list(bkt.objects.filter(Prefix='index'))) # One request, doesnt return tons of data! for i,obj in enumerate(bkt.objects.all()): # 1348 items - 2 requests, and boto does it for me. print i, obj.key, obj.size # does not fetch the actual object, score if i > 10000: break print '\n--- Body reads ---' print obj.get()['Body'].read() # from iteration print bkt.Object('zuxisaki').get()['Body'].read() # by name print '\n--- Body write ---' data = 'A'*128 nm = RandChars(8) bkt.Object(nm).put(Body=data) print 'Wrote key=',nm # Is Best rand chars