def verify_s3_bucket_exists(s3_bucket_name):
"""
Check whether S3 bucket exists
Args:
s3_bucket_name (str): The s3 bucket name
Returns:
list: if connection established and bucket found, return list of
objects in bucket otherwise error and exit on any issues trying
to list objects in bucket.
"""
ls_s3_bucket_cmd = 'aws s3api head-bucket --bucket {}'.format(s3_bucket_name)
try:
subprocess.run(ls_s3_bucket_cmd, check=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except subprocess.SubprocessError:
logger.exception("Failed to list specified s3 bucket: {}", s3_bucket_name)
sys.exit("[-] Failed to list specified s3 bucket")
评论列表
文章目录