0
votes

My implementation of AmazonDynamoDBv2's AmazonDynamoDBAsync.queryAsync with a QueryRequest is returning a code 400 "Query condition missed key schema element ..." when I am querying on a GSI.

I have tried using both the DynamoDBAttribute name ("myAttr") AND the GSI's actual index name ("idx_global_myAttr") and receive the same error code. This is running against the Docker image "amazon/dynamodb-local".

I have read the DynamoDB docs on GSIs, but I cannot figure out how to target the secondary index in this query. It seems to only respond to the primary index.

Table Description: `

tableDescription: {
  attributeDefinitions: {
    {
      "attributeName": "myAttr",
      "attributeType": "S"
    },
    {
      "attributeName": "id",
      "attributeType": "S"
    }
  },
...
  "tableName": "myTable",
...
  "globalSecondaryIndexes": [
    {
      "indexName": "idx_global_ myAttr",
      "keyType": "HASH"
    }
  ]
...
}

`

QueryRequest:

`
var attributeValue = new AttributeValue().withS(value);
var expressionAttributeValueMap = Map.of(":v1", attributeValue);
var queryRequest = new QueryRequest("myTable")
  .withExpressionAttributeValues(expressionAttributeValeMap)
  .withKeyConditionExpression("myAttr = :v1");
`
1

1 Answers

0
votes

SOLVED:

Specify which index the QueryRequest is for by adding .withIndex("idx_global_myAttr") to the QueryRequest builder and use the attribute name ("myAttr") in the KeyCondidtionExpression.