def is_valid_s3_bucket(s3_string):
"""
Determine if the input string starts with a valid s3 bucket name
:param s3_string: an aws s3 address (e.g. s3://mybucket/other...)
:return: True if the s3_string contains a valid bucket name
"""
client = boto3.client('s3')
# only applies to s3 - so ignore otherwise
if s3_string[0:5] != 's3://':
return False
# get the bucket name
bucket = s3_string[5:].strip('/').split('/')[0]
if not bucket:
return False
# see if bucket exists
try:
client.list_objects(Bucket=bucket)
except:
return False
return True
评论列表
文章目录