rombob
rombob

Reputation: 195

Why storage class attribute is missing for boto3 s3 object?

When running retrieval of Storage Class

import boto3

s3 = boto3.resource('s3')
key = s3.Object('bucket_name','key')
print key.storage_class

it returns None

Upvotes: 2

Views: 748

Answers (2)

DenisTs
DenisTs

Reputation: 130

Per AWS documentation: S3 returns x-amz-storage-class header for all objects except Standard storage class. https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html

I'm using the following to get storage class variable:

import boto3

session = boto3.session.Session(profile_name='dev')
s3_resource = session.resource('s3', region_name=region)                 
obj_meta = s3_resource.Object(bucket, key_object)

obj_storage_class = 'STANDARD' if obj_meta.storage_class is None else str(obj_meta.storage_class)

Upvotes: 2

John Rotenstein
John Rotenstein

Reputation: 270114

My experimenting shows that Standard storage class returns a value of None (as it did for you).

However, I managed to obtain valid values for other storage classes such as STANDARD_IA and GLACIER.

Upvotes: 1

Related Questions