[英]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())
. 使用Python 3.6和boto3在AWS Lambda上检索对象列表时,对象的LastModified
属性使用'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. 当我在本地运行程序时,此属性使用'LastModified': datetime.datetime(2018, 8, 17, 1, 51, 31, tzinfo=tzutc())
是'LastModified': datetime.datetime(2018, 8, 17, 1, 51, 31, tzinfo=tzutc())
,这是我想要的。
Why is this happening? 为什么会这样呢? Is there a workaround that will allow me to specify UTC as part of the request? 有没有一种解决方法可以让我将UTC指定为请求的一部分? Alternatively, is there a simple way to convert these datetime
s to UTC after they're returned from S3? 另外,是否有一种简单的方法可以将这些datetime
从S3返回后转换为UTC?
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: 结果是d_utc
为:
datetime.datetime(2018, 8, 16, 15, 51, 31, tzinfo=tzutc())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.