Python Monitor S3 Last Update Time

Python Monitor S3 Last Update Time

Install boto3
https://github.com/boto/boto3

>sudo pip install boto3

AWS credentials will be in ~/.aws/credentials
>cat ~/.aws/credentials
[default]
aws_access_key_id = xxxxx
aws_secret_access_key = xxxxxxxx

Region is set there as well
>cat ~/.aws/config
[default]
region = us-east-1

List all the buckets
>import boto3
>>> s3 = boto3.resource('s3')
>>> for bucket in s3.buckets.all():
...         print(bucket.name)
...

Check the last modified time in S3
>>> client = boto3.client('s3')
>>> obj = client.get_object(Bucket='j2c-production', Key='feed-2g/jobs_2g.txt.gz')
>>> print(obj['LastModified'])
2017-12-12 16:31:32+00:00


References:
https://stackoverflow.com/questions/9679344/how-can-i-get-last-modified-datetime-of-s3-objects-with-boto
https://github.com/boto/boto3
http://blog.csdn.net/leexide/article/details/17630853

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326446669&siteId=291194637