-1

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?

SwiftMiner
  • 47
  • 5

1 Answers1

0

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"
Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31
  • The Syntax is correct. I need to write it like that because i'm using f'strings. I found the problem. My JupyterNotebook Kernel had still the connection to the old DynamoDB. After restarting the kernel, everything worked fine. – SwiftMiner Dec 13 '22 at 18:07