小编Hen*_*ler的帖子

BatchGetItem 操作上的 DynamoDB 和 Boto3 错误:“提供的关键元素与架构不匹配”

我在 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
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

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',
        }
    }
)
Run Code Online (Sandbox Code Playgroud)

这是表中项目的屏幕截图。

这是表详细信息的屏幕截图,显示分区键是“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', …
Run Code Online (Sandbox Code Playgroud)

nosql python-3.x amazon-dynamodb boto3 dynamodb-queries

4
推荐指数
1
解决办法
2613
查看次数