简体   繁体   中英

Force AWS Lambda to use UTC when listing S3 objects using boto3

When retrieving a list of objects on AWS Lambda using Python 3.6 and boto3, the objects' LastModified attribute is using 'LastModified': datetime.datetime(2018, 8, 17, 1, 51, 31, tzinfo=tzlocal()) .

When I run my program locally, this attribute is using 'LastModified': datetime.datetime(2018, 8, 17, 1, 51, 31, tzinfo=tzutc()) , which is what I want.

Why is this happening? Is there a workaround that will allow me to specify UTC as part of the request? Alternatively, is there a simple way to convert these datetime s to UTC after they're returned from S3?

Running this code:

from datetime import datetime
from dateutil import tz
from dateutil.tz import tzlocal

d_local = datetime(2018, 8, 17, 1, 51, 31, tzinfo=tzlocal())

d_utc = d_local.astimezone(tz.tzutc())

The result is that d_utc is:

datetime.datetime(2018, 8, 16, 15, 51, 31, tzinfo=tzutc())

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM