I`m using python boto3 to work with dynamodb. I've created a table using the following script:
cls.table = dynamodb.create_table(
TableName='table-unittest',
KeySchema=[
{
'AttributeName': 'id',
'KeyType': 'HASH',
},
{
'AttributeName': 'user_name',
'KeyType': 'RANGE',
}
],
AttributeDefinitions=[
{
'AttributeName': 'id',
'AttributeType': 'N',
},
{
'AttributeName': 'user_name',
'AttributeType': 'S',
},
{
'AttributeName': 'age',
'AttributeType': 'N',
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 2,
'WriteCapacityUnits': 2,
},
GlobalSecondaryIndexes=[
{
'IndexName': 'age-index',
'KeySchema': [
{
'AttributeName': 'age',
'KeyType': 'HASH',
},
],
'Projection': {
'ProjectionType': 'KEYS_ONLY',
},
'ProvisionedThroughput': {
'ReadCapacityUnits': 2,
'WriteCapacityUnits': 2,
}
},
],
)
But, when querying the table by its age-index
global secondary index, i receive the following message:
Query condition missed key schema element: age
Here is the params i pass to the boto3 query method:
{
'ConsistentRead': False,
'IndexName': 'age-index',
'QueryFilter': {
'age': {
'ComparisonOperator': 'GT',
'AttributeValueList': [18]
}
},
'TableName': 'table-unittest',
'ScanIndexForward': False,
'KeyConditions': {
'id': {
'ComparisonOperator': 'EQ',
'AttributeValueList': [222]
}
}
}