def check_s3_file_exists(s3_path, file_name):
"""
Determine if a s3 key exists
:param s3_path: an s3 "directory" path (e.g. s3://mybucket/name/)
:param file_name: a pathless file name (e.g. myfile.txt)
:return: True if key exists; False otherwise
"""
full_path = s3_path.rstrip('/') + '/' + file_name
bucket_name, key_prefix = full_path[5:].split("/", 1)
client = boto3.client('s3')
# see if file exists
try:
client.get_object(Bucket=bucket_name, Key=key_prefix)
except:
return False
return True
评论列表
文章目录