cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to check if a key exists in a bucket in s3 using boto3?

Kaniz
Community Manager
Community Manager
 
1 ACCEPTED SOLUTION

Accepted Solutions

Kaniz
Community Manager
Community Manager

We can check using this method:-

import boto3

from botocore.errorfactory import ClientError

s3 = boto3.client('s3')

try:

s3.head_object(Bucket='bucket_name', Key='file_path')

except ClientError:

# Not found

pass

View solution in original post

1 REPLY 1

Kaniz
Community Manager
Community Manager

We can check using this method:-

import boto3

from botocore.errorfactory import ClientError

s3 = boto3.client('s3')

try:

s3.head_object(Bucket='bucket_name', Key='file_path')

except ClientError:

# Not found

pass

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.