0
votes

I have a dynamoDB table called Bank-Statements.

It has a Primary partition key:-

  • Name: TransactionID (Number)

It has an Index:-

  • Name: StatementType-index
  • Status: Active
  • Type: GSI
  • Partition Key: StatementType (String)

In the StatementType column there are several records marked "RBS"

I wrote this in C#:

    public async Task<string> GetRecordList()
    {
        try
        {
            var request = new QueryRequest
            {
                TableName = "Bank-Statements",
                KeyConditionExpression = "StatementType = :searchKey",
                ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
                    {":searchKey", new AttributeValue { S =  "RBS" }}}
            };

            var response = await dynamoDbClient.QueryAsync(request);  //Error occurs here

            foreach (Dictionary<string, AttributeValue> item in response.Items)
            {
        //do something with item
            }
        }
        catch (Exception e)
        {
            logger.Info("Failed while Getting Record List");
            logger.Info("Error: " + e.Message);
        }

        return "DONE";
    }

I'm getting this error "Query condition missed key schema element: TransactionID"

Why am I getting this when I'm using the StatementType-index as the key?

1

1 Answers

0
votes

In a different tutorial I found this setting:

IndexName = "StatementType-index".

This code works:

public async Task<string> GetRecordList()
{
    try
    {
        var request = new QueryRequest
        {
            TableName = "Bank-Statements",
            IndexName = "StatementType-index",
            KeyConditionExpression = "StatementType = :searchKey",
            ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
                {":searchKey", new AttributeValue { S =  "RBS" }}}
        };

        var response = await dynamoDbClient.QueryAsync(request);  //Error occurs here

        foreach (Dictionary<string, AttributeValue> item in response.Items)
        {
    //do something with item
        }
    }
    catch (Exception e)
    {
        logger.Info("Failed while Getting Record List");
        logger.Info("Error: " + e.Message);
    }

    return "DONE";
}