是否可以将日期时间保存到 DynamoDB?

问题描述

我有下一个代码:

users_table = Table(users_table_name, connection=Core.aws_dynamodb_connection)
users_table.put_item(data={
  "login": login,
  "password": hashlib.sha256(password.encode("utf-8")).hexdigest(),
  "profile": profile,
  "registration_date": datetime.now() # PROBLEM IS HERE
})

但是当我运行它时,它失败并出现错误:

But when I run it, it fails with error:

TypeError:值2015-01-12 05:02:57.053131"的不支持类型< type 'datetime.datetime'>"

TypeError: Unsupported type "< type 'datetime.datetime' >" for value "2015-01-12 05:02:57.053131"

我尝试了很多方法,但似乎无法将 datetime 保存到 DynamoDB.顺便说一句,它在 MongoDB 中运行良好.

I've tried a lot of ways, but it seems that it isn't possible to save datetime to DynamoDB. Btw it works fine in MongoDB.

有什么解决办法吗?


解决方案

好的,我看到 DynamoDB 不支持任何日期类型.所以唯一的解决方案是使用类unix的时间作为整数,或者将日期保存为字符串.

Okay, I see that DynamoDB does not support any date types. So the only solution is to use unix-like time as integer, or save date as string.

相关文章