在Golang中查询DynamoDB上的二级索引

My primary key is a field called "id"

I've added a secondary index to my table on the field "group_number"

enter image description here

I query via the secondary index like so:

// Query the secondary index
queryInput := &dynamodb.QueryInput{
    TableName: aws.String(c.GetDynamoDBTableName()),
    KeyConditions: map[string]*dynamodb.Condition{
        "group_number": {
            ComparisonOperator: aws.String("EQ"),
            AttributeValueList: []*dynamodb.AttributeValue{
                {
                    S: aws.String(c.GroupNumber),
                },
            },
        },
    },
}

However; I get the error "validationexception: query condition missed key schema element: id"

Does DynamoDB only allow the querying of primary keys? I was under the impression you use "GetItem" for primary key being that only one record can come back if you use a primary key. To search via secondary indexes you use "Query", and to search by non-index keys, you use "Scan".

Please let me know what I'm doing incorrectly here.

In addition to the TableName, You need to also specify the IndexName property when creating the QueryInput to query the index.

https://docs.aws.amazon.com/sdk-for-go/api/service/dynamodb/#QueryInput

// The name of an index to query. This index can be any local secondary index
// or global secondary index on the table. Note that if you use the IndexName
// parameter, you must also provide TableName.
IndexName *string `min:"3" type:"string"`