I have a python script in AWS Lambda that I started (very basic). I got results after a few tries and now I am trying to scan the data to determine if any of the "LastModified" dates are more than 4 hours old (based on the current date and time).
Is there any simple way to do that?
import boto3
import os
from datetime import datetime
def lambda_handler(event, context):
s3 = boto3.client('s3')
bucket = 'mybucket'
resp = s3.list_objects_v2(Bucket=bucket, Prefix='JSON/')
print(resp['Contents'])
Here is a sample of the response (list of dicts)
[{'Key': 'JSON/File1.json', 'LastModified': datetime.datetime(2019, 5, 28, 18, 11, 42, tzinfo=tzlocal()), 'ETag': '"d41d8cd98f00b204e9800998ecf8427e"', 'Size': 0, 'StorageClass': 'STANDARD'}, {'Key': 'JSON/File2.json', 'LastModified': datetime.datetime(2020, 8, 6, 12, 55, 9, tzinfo=tzlocal()), 'ETag': '"e8534a11ac08968619c05e28641a09b8"', 'Size': 7600141, 'StorageClass': 'STANDARD'}, {'Key': 'JSON/File3.json', 'LastModified': datetime.datetime(2020, 8, 6, 12, 56, 9, tzinfo=tzlocal()), 'ETag': '"bac4bfc4daa1f4a4982b9ec0c5f11c62"', 'Size': 38430159, 'StorageClass': 'STANDARD'}