这是我的 python lambda 函数的相关部分:
def retrivearticle(id):
"""function that return a specific article"""
data = client.get_item(
TableName=os.environ.get("STORAGE_GIODEMWEBSITE_NAME"),
Key={
'id': {
'S': id
}
}
)
data = fromLowLevelToPython(data)
return data
fromLowLevelToPython 在哪里:
def fromLowLevelToPython(data):
"""Convert low-leve dynamodb response into regular json"""
deserializer = TypeDeserializer()
python_data = {k: deserializer.deserialize(v) for k, v in data.items()}
return python_data
然后我的发电机数据库表中有这个项目: enter image description here enter image description here
{
"id": {
"S": "test"
},
"value": {
"S": "test"
}
}
当我运行查询时出现此错误
[ERROR] TypeError: Dynamodb type id is not supported
Traceback (most recent call last):
File "/var/task/index.py", line 21, in handler
response = retrivearticle(id)
File "/var/task/index.py", line 54, in retrivearticle
data = fromLowLevelToPython(data)
File "/var/task/index.py", line 70, in fromLowLevelToPython
python_data = {k: deserializer.deserialize(v) for k, v in data.items()}
File "/var/task/index.py", line 70, in <dictcomp>
python_data = {k: deserializer.deserialize(v) for k, v in data.items()}
File "/var/task/boto3/dynamodb/types.py", line 269, in deserialize
raise TypeError(
你知道这里有什么问题吗?
如果我在本地尝试它似乎可以正常工作:
In [13]: import boto3
In [14]: from boto3.dynamodb.types import TypeDeserializer
In [15]: ll = {
...: "id": {
...: "S": "test"
...: },
...: "value": {
...: "S": "test"
...: }
...: }
In [16]: def fromLowLevelToPython(data):
...: """Convert low-leve dynamodb response into regular json"""
...: deserializer = TypeDeserializer()
...: python_data = {k: deserializer.deserialize(v) for k, v in data.items()}
...: return python_data
...:
In [17]: fromLowLevelToPython(ll)
Out[17]: {'id': 'test', 'value': 'test'}