【发布时间】:2020-05-23 04:26:47
【问题描述】:
我正在尝试使用 alexa 从我的 dynamo db 表中读取数据,但我的 lambda 函数似乎无法访问我的表。 这是从 dynamodb 获取数据的代码:
# Gets the data from dynamodb based on userid
def GetData(session):
userId = session['user']['userId'].split('.')
userId = userId[3]
try:
response = table.query(
KeyConditionExpression=Key('guid').eq(str(userId))
)
# print ("Got data: " + str(len(response)))
print(response)
for item in response['Items']:
final_response = item["command"]
tstamp = item["tstamp"]
if (response['Count'] == 0):
final_response = "No Data with this userid. You can ask to get the userid"
else:
now = datetime.datetime.utcnow()
timestamp = int(round((now - datetime.datetime(2016, 1, 1)).total_seconds()))
if ((timestamp - int(tstamp)) > 60):
final_response = "No Data received from device in past 1 minute"
return final_response
except ClientError as e:
print(e.response['Error']['Message'])
当我向 Alexa 询问我的自定义问题时,我得到的唯一回答是没有此用户 ID 的数据。您可以要求获取用户 ID。 当我测试运行我的 lambda 函数时,它运行成功。但它没有查询数据库。
【问题讨论】:
-
我不是 python 人,但错误似乎表明您在
event对象上请求密钥“会话”,并且它不存在。 -
我设法消除了错误。但是 lambda 函数仍然没有从 Dynamo db 中读取数据。当我触发 alexa 时,她只是说:“此用户 ID 没有数据。您可以要求获取用户 ID”。
标签: python-3.x aws-lambda amazon-dynamodb alexa-skills-kit