Madhukar Mohanraju
Madhukar Mohanraju

Reputation: 2863

boto3 s3 head_object method is returning Storage class as None

Code:

import boto3

s3_cli = boto3.client('s3')
object_summary = s3_cli.head_object(
        Bucket='test-cf',
        Key='RDS.template',
        VersionId='szA3ws4bH6k.rDXOEAchlh1x3OgthNEB'
    )

print('LastModified: {}'.format(object_summary.get('LastModified')))
print('StorageClass: {}'.format(object_summary.get('StorageClass')))
print('Metadata: {}'.format(object_summary.get('Metadata')))
print('ContentLength(KB): {}'.format(object_summary.get('ContentLength')/1024))

Output:

LastModified: 2017-06-08 09:22:43+00:00
StorageClass: None
Metadata: {}
ContentLength(KB): 15

Am unable to get the StorageClass of the key using boto3 sdk. I can see the storage class set as standard from the aws console. I have also tried using s3.ObjectSummary and also s3.ObjectVersion methods in boto3 s3 resouces, but they also returned None.

Upvotes: 1

Views: 4647

Answers (1)

helloV
helloV

Reputation: 52433

Not sure why it is returning None. Meanwhile, use the following code to get the storage class. Let me check my version of Boto3.

bucket = s3.Bucket('test-cf')
for object in bucket.objects.all():
  print object.key, object.storage_class

Upvotes: 1

Related Questions