def check_s3(self, bucket, element): # pragma: no cover
"""This method is a helper con `cache_s3`.
Read method `cache_s3` for more information.
:param bucket:
:param element:
:return:
"""
session = boto3.Session(profile_name=self.profile_name)
s3 = session.resource('s3')
try:
s3.meta.client.head_bucket(Bucket=bucket)
except ClientError:
# If the bucket does not exists then simply use the original
# I silently fail returning everything as it is in the url
return False
try:
# If the key does not exists do not return False, but try to
# create a readonly user in order to not have problems into the
# travis environment.
s3.Object(bucket, element).load()
except ClientError:
return False
else:
return True
评论列表
文章目录