这个问题此刻让我心碎不已。我正在尝试学习python、lambda和Dynamodb。
Python看起来很棒,我可以使用像Xampp这样的普通MySQL服务器连接到MySQL,我的目标是学习如何使用Dynamodb,但不知何故我无法从Dynamodb中使用get_items。这真的很让我头疼,而且已经持续了两天了。
我看了大量的youtube电影并阅读了aws文档。
任何线索我做错了什么。我到现在为止的代码;
import json
import boto3
from boto3.dynamodb.conditions import Key, Attr
#always start with the lambda_handler
def lambda_handler(event, context):
# make the connection to dynamodb
dynamodb = boto3.resource('dynamodb')
# select the table
table = dynamodb.Table("html_contents")
# get item from database
items = table.get_item(Key={"id": '1'})
无论我往哪里看,我都认为我应该这样做。但我一直收到以下错误
{errorMessage=An error occurred (ValidationException) when calling the GetItem operation: The provided key element does not match the schema, errorType=ClientError, stackTrace=[["\/var\/task\/lambda_function.py",16,"lambda_handler","\"id\": '1'"],["\/var\/runtime\/boto3\/resources\/factory.py",520,"do_action","response = action(self, *args, **kwargs)"],["\/var\/runtime\/boto3\/resources\/action.py",83,"__call__","response = getattr(parent.meta.client, operation_name)(**params)"],["\/var\/runtime\/botocore\/client.py",314,"_api_call","return self._make_api_call(operation_name, kwargs)"],["\/var\/runtime\/botocore\/client.py",612,"_make_api_call","raise error_class(parsed_response, operation_name)"]]}
我的数据库结构。
我的DynamoDb设置表名html_contents主分区密钥id (编号)主排序密钥时间点恢复DISABLEDEnable加密已禁用生存时间属性DISABLEDManage TTL表状态处于活动状态
我在这里做错了什么?我开始觉得我在aws的配置上做错了什么。
提前谢谢你。
韦斯利
发布于 2021-05-30 23:02:25
您之所以会遇到这个问题,是因为您已经创建了一个具有数据类型为整数的分区键的表。现在,您正在执行一个read an item操作,将分区指定为一个字符串,该字符串需要是一个导致此问题的整数。
我是Lucid-Dynamodb的作者,这是一个亚马逊网络服务DynamoDB的极简主义包装器。它涵盖了Dynamodb的所有操作。
参考: https://github.com/dineshsonachalam/Lucid-Dynamodb#4-read-an-item
https://stackoverflow.com/questions/53311721
复制相似问题