I would like to know if a key exists in boto3. I can loop the bucket contents and check the key if it matches.
But that seems longer and an overkill. Boto3 official
Try This simple
import boto3 s3 = boto3.resource('s3') bucket = s3.Bucket('mybucket_name') # just Bucket name file_name = 'A/B/filename.txt' # full file path obj = list(bucket.objects.filter(Prefix=file_name)) if len(obj) > 0: print("Exists") else: print("Not Exists")