Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the S3 key's created date with boto?

Boto's S3 Key object contains last_modified date (which is nicely available via parse_ts, thanks @Gaarnat!) but the base_field "date" (i.e., ctime) doesn't seem to be accessible, even though it's listed in key.base_fields.

Based on the table at http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html, it does seem that it is always automatically created (and I can't imagine a reason why it wouldn't be). It's probably just a simple matter of finding it somewhere in the object attributes, but I haven't been able to find it so far, although I did find the base_fields attribute which contains 'date'. (They're just a set and don't seem to have an available methods and I haven't been able to find documentation regarding ways to inspect them.)

For example, Amazon S3 maintains object creation date and size metadata and uses this information as part of object management.

Interestingly, create_time (system metadata field "Date" in link above) does not show up in the AWS S3 console, either, although last_modified is visible.

like image 791
fatal_error Avatar asked Jan 02 '15 18:01

fatal_error


People also ask

What is Boto3 resource (' S3 ')?

Python, Boto3, and AWS S3: Demystified At its core, all that Boto3 does is call AWS APIs on your behalf. For the majority of the AWS services, Boto3 offers two distinct ways of accessing these abstracted APIs: Client: low-level service access. Resource: higher-level object-oriented service access.

How do I know if my S3 file is Boto3?

Boto3 resource doesn't provide any method directly to check if the key exists in the S3 bucket. Hence, you can load the S3 object using the load() method. If there is no exception thrown, then the key exists. If there is a client error thrown and the error code is 404 , then the key doesn't exist in the bucket.

How do I authenticate an S3 bucket in Python?

Set Up Credentials To Connect Python To S3Sign in to the management console. Search for and pull up the S3 homepage. Next, create a bucket. Give it a unique name, choose a region close to you, and keep the other default settings in place (or change them as you see fit).


1 Answers

Answering the old question, just in case others run into the same issue.

Amazon S3 maintains only the last modified date for each object. For example, the Amazon S3 console shows the Last Modified date in the object Properties pane. When you initially create a new object, this date reflects the date the object is created. If you replace the object, the date changes accordingly. So when we use the term creation date, it is synonymous with the term last modified date.

Reference: https://docs.aws.amazon.com/AmazonS3/latest/dev/intro-lifecycle-rules.html

like image 150
sameer_v Avatar answered Sep 27 '22 22:09

sameer_v