Use python to extract the last modified date for TIFF file in S3 bucket

1634
1
Jump to solution
11-14-2023 08:07 AM
haoechibubao
New Contributor

Hello community, does anyone know how to use python to get the last modified date for raster dataset? In my case, I have some TIFF files in S3 bucket, which is a cloud storage store. I want to scan folders and identify the newly added TIFF dataset. Instead of using the specific package for aws bucket, is it possible to use arcpy or arcgis api for python to get the modified date from the property headers?

Screenshot 2023-11-14 110522.png

Thanks in advance!

Han

0 Kudos
1 Solution

Accepted Solutions
EarlMedina
Esri Regular Contributor

I would lean towards using the boto3 package to get that info. I would assume it's the same as you would get through the metadata, hopefully. There are a couple of ways to do this, but they all pretty much entail getting a "last_modified" attribute.

 

import boto3
s3 = boto3.client('s3', region_name='your_region')
objects = s3.list_objects(Bucket='your_bucket')

for o in objects["Contents"]:
    print(o["LastModified"])

View solution in original post

1 Reply
EarlMedina
Esri Regular Contributor

I would lean towards using the boto3 package to get that info. I would assume it's the same as you would get through the metadata, hopefully. There are a couple of ways to do this, but they all pretty much entail getting a "last_modified" attribute.

 

import boto3
s3 = boto3.client('s3', region_name='your_region')
objects = s3.list_objects(Bucket='your_bucket')

for o in objects["Contents"]:
    print(o["LastModified"])