DynamoDB GSIs query doesn't find GSI3 & GSI4 despite they exist

261 Views Asked by At

I am working with DynamoDB and testing queries with boto3 and VS Code at the moment. First i only had 2 GSIs and the queries worked fine. Now i created a third and a fourth one.

When trying to query GSI3 and GSI4 i get the following error:

ClientError: An error occurred (ValidationException) when calling the ExecuteStatement operation: The table does not have the specified index

Here is my query code for GSI3:

import boto3 
import pprint as pp

# dynamodb client 
dynamodb_client = boto3.client('dynamodb')

# Table Name 
table_name_4 = "test_db.GSI3"

# get item 
telefon = '4A4EBBF4044C8938AC4E3FF11C7D1D16'
stmt = f"SELECT * FROM {table_name_4} WHERE telefon=?"
pmt =[{ "S": telefon }] 

resp = dynamodb_client.execute_statement( Statement=stmt , Parameters=pmt ) 

pp.pprint(resp['Items'])

Here is my query code for GSI2 that works fine:

import boto3 
import pprint as pp

# dynamodb client 
dynamodb_client = boto3.client('dynamodb')

# Table Name 
table_name_3 = "test_db.GSI2"

# get item 
personal_accept = 'FALSCH'
stmt = f"SELECT * FROM {table_name_3} WHERE personal_accept=?"
pmt =[{ "S": personal_accept }] 

resp = dynamodb_client.execute_statement( Statement=stmt , Parameters= pmt ) 

#pp.pprint(resp['Items'])
pp.pprint(resp['Items'][0]["titel"])
pp.pprint(resp['Items'][0]["sk"])
pp.pprint(resp['Items'][0]["date"])

All GSIs are active

enter image description here

Anybody has an idea what is going wrong?

1

There are 1 best solutions below

1
On

Your syntax is wrong for specifying an index for PartiQL, it should be as follows:

"Table"."Index", or in your case "test_db"."GSI3" etc....

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.select.html#ql-reference.select.parameters

SELECT * 
FROM "TableName"."IndexName"