简体   繁体   中英

Boto3 DynamoDB - Scan Table Parameter validation failed

Hi I am trying to read data from a DynamoDB table using Boto3. 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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