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
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
.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.