Getting botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found in BOTO3 while trying to create a s3 object

0

I have a list of s3 Objects .i want to get the count of keys in Glacier and archive. Here is my code

s3 = boto3.resource(service_name='s3', aws_access_key_id=accesskey, aws_secret_access_key=secretkey)
count = 0
# latest object is a list of s3 keys
for obj in latest_objects:
    try:
        response = s3.Object(Bucket, obj)
        if response.storage_class in ['GLACIER', 'DEEP_ARCHIVE']:
            count=count+1
            print("To be restored: " + obj)
   except Exception as e:
       print(str(e))
       break

when I run this code I am getting botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found for some s3 keys. when I verified these keys are present in bucket. Not sure what's wrong, Again this happens only for some of the keys for the rest of the keys response = s3.Object(Bucket, obj) works fine

Any help is much appreciated

gefragt vor einem Jahr10073 Aufrufe
1 Antwort
0

When you create a folder via s3 console, it creates an object with the name appended by suffix "/" and that object is displayed as a folder in the s3 console. So it will be returned on a HeadObject operation.

But if you create the file test1/test2/file.txt that's just the name of the file, it doesn't create test1/ and test2/ for you. Object storage is a flat file structure unlike block storage.

When you create a folder from the console it mentions that behavior as well: Guide to solve the querry

beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen