question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ParamValidationError when using DynamoDB paginator

See original GitHub issue

I create a DynamoDB paginator like this:

    paginator = client.get_paginator('query')
    page_iterator = paginator.paginate(
        TableName=TABLE_NAME,
        IndexName=INDEX_NAME,
        KeyConditionExpression=Key('X').eq(x) & Key('Y').lte(y)
    )
    for page in page_iterator:
        print (page['Items'])
    return

When I run it, I receive the following error:

Exception has occurred: ParamValidationError
Parameter validation failed:
Invalid type for parameter KeyConditionExpression, value: <boto3.dynamodb.conditions.And object at 0x111524110>, type: <class 'boto3.dynamodb.conditions.And'>, valid types: <class 'str'>

The exact same KeyConditionExpression works when I query the table directly:

    result = table.query(
        IndexName=INDEX_NAME,
        KeyConditionExpression=Key('X').eq(x) & Key('Y').lte(y)
    )

BTW: Documentation says that KeyConditionExpression should be a string and not some condition built this way.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

20reactions
kulbidacommented, Apr 17, 2020

I am having the same issue with KeyConditionExpression for query and paginator

dynamodb = boto3.client('dynamodb',  . . . )
items = dynamodb.query(TableName='test',
    KeyConditionExpression=Key('user_email').eq('test@example.com'))

using paginator:

paginator = dynamodb.get_paginator('query')
items = paginator.paginate(TableName='test',
    KeyConditionExpression=Key('user_email').eq('test@example.com'))

getting:

Invalid type for parameter KeyConditionExpression,
value: <boto3.dynamodb.conditions.Equals object at 0x7f286128e990>,
type: <class 'boto3.dynamodb.conditions.Equals'>, valid types: <class 'str'>
6reactions
swetashrecommented, Feb 24, 2020

@usegev - We have a customization around resources that converts KeyConditionExpression type to string format that’s why you are not getting error when query the table directly.

You can use the same format with paginator by using resource.meta.client. Something like this:

import boto3
res = boto3.resource('dynamodb')

paginator = res.meta.client.get_paginator('query')
page_iterator = paginator.paginate(
        TableName=TABLE_NAME,
        IndexName=INDEX_NAME,
        KeyConditionExpression=Key('X').eq(x) & Key('Y').lte(y)
    )

Hope it helps and please let me know if you have any questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add filter expressions to paginated Boto3 dynamodb scan
I am attempting to filter a paginated scan request to a dynamodb table. While a traditional scan filter would use ...
Read more >
DynamoDB — Boto3 Docs 1.26.34 documentation - AWS
With DynamoDB, you can create database tables that can store and retrieve any amount of data, and serve any level of request traffic....
Read more >
How to use the botocore.exceptions.ParamValidationError ...
ParamValidationError function in botocore. To help you get started, we've selected a few botocore examples, based on popular ways it is used in...
Read more >
Paginating table query results - Amazon DynamoDB
Learn to use pagination when querying Amazon DynamoDB tables. Use paginating when you need the ability to easily page through a query's result...
Read more >
Querying against a DynamoDB Primary Key with Boto3
I'm familiar enough with DynamoDB to know (and have experienced) a ... ParamValidationError: Parameter validation failed: Invalid length for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found