我在使用 Boto3/DynamoDB BatchGetItem操作时遇到了困难。我将不胜感激任何帮助或指导!如果这是一个新手问题,我对 python/aws 很陌生,所以很抱歉。
当我执行操作时,我收到此错误:
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the BatchGetItem operation: The provided key element does not match the schema
这是我的代码:
import boto3
dynamodb = boto3.resource('dynamodb', region_name='us-west-2')
response = dynamodb.batch_get_item(
RequestItems={
'test': {
'Keys': [
{
'item_ID': {
'S': '1'
}
},
{
'item_ID': {
'S': '2'
}
}
],
'ProjectionExpression': 'item_ID, color',
}
}
)
这是表详细信息的屏幕截图,显示分区键是“item_ID”并且它是“字符串”
这是完整的错误消息:
Traceback (most recent call last):
File "C:/Users/Henry Miller/PycharmProjects/bioinformatics_webapp/get_items.py", line 18, in <module>
'ProjectionExpression': 'item_ID, color',
File "C:\Users\Henry Miller\PycharmProjects\bioinformatics_webapp\venv\lib\site-packages\boto3\resources\factory.py", line 520, in do_action
response = action(self, *args, **kwargs)
File "C:\Users\Henry Miller\PycharmProjects\bioinformatics_webapp\venv\lib\site-packages\boto3\resources\action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "C:\Users\Henry Miller\PycharmProjects\bioinformatics_webapp\venv\lib\site-packages\botocore\client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "C:\Users\Henry Miller\PycharmProjects\bioinformatics_webapp\venv\lib\site-packages\botocore\client.py", line 612, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the BatchGetItem operation: The provided key element does not match the schema