I am trying to write python program that checks if path exists or not. For example, given the path /root/subfolder1/subfolder2/, I want to pass this path to the S3 API to check whether this path exists in AWS S3 or not.
I have tried this, but it is not full-fledged solution for my requirement:
import boto3
import botocore
client = boto3.client('s3',aws_access_key_id=AccessKey, aws_secret_access_key=SecretAccessKey,region_name='us-east-1')
result = client.list_objects(Bucket=full_poc", Prefix="sub_folder1/sub_folder2/full" )
print(result)
exist = False
if "Contents" in result:
exist = True
print(exist)
With this code, even if I pass sub instead of sub_folder1 it prints True.
What are other ways to solve this problem?