简体   繁体   English

Boto3 DynamoDB - 扫描表参数验证失败

[英]Boto3 DynamoDB - Scan Table Parameter validation failed

Hi I am trying to read data from a DynamoDB table using Boto3.您好我正在尝试使用 Boto3 从 DynamoDB 表中读取数据。 I am trying to run the code below but am getting the following error:我正在尝试运行下面的代码,但出现以下错误:

Unknown parameter in input: "KeyConditionExpression", must be one of: TableName, IndexName, AttributesToGet, Limit, Select, ScanFilter, ConditionalOperator, ExclusiveStartKey, ReturnConsumedCapacity, TotalSegments, Segment, ProjectionExpression, FilterExpression, ExpressionAttributeNames, ExpressionAttributeValues, ConsistentRead

Python code I am trying to run:我正在尝试运行的 Python 代码:

client = boto3.client('dynamodb', region_name='eu-west-1')

customers_table = '-customers'

def dump_table(table_name):
    results = []
    last_evaluated_key = None
    while True:
        if last_evaluated_key:
            response = client.scan(
                TableName=table_name,
                KeyConditionExpression="sort = :sort_key and deletedDate < :firstIngestionDate",
                ExpressionAttributeValues={":sort_key": {"S": "DELETION_EVENT"},
                                           ":firstIngestionDate": {"S": "2021-01-27T23:26:58.280Z"}},
                ExclusiveStartKey=last_evaluated_key
            )
        else:
            response = client.scan(TableName=table_name,
                                   KeyConditionExpression='sort = :sort_key and deletedDate < :firstIngestionDate',
                                   ExpressionAttributeValues={":sort_key": {"S": "DELETION"},
                                                              ":firstIngestionDate": {"S": "2021-01-27T23:26:58.280Z"}})
        last_evaluated_key = response.get('LastEvaluatedKey')
        results.extend(response['Items'])
        if not last_evaluated_key:
            break
    return results


data = dump_table(customers_table)

I ended up replacing "KeyConditionExpression" for "FilterExpression" and that seems to have done the trick.我最终将“KeyConditionExpression”替换为“FilterExpression”,这似乎成功了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM