We have a DynamoDB table:
resource "aws_dynamodb_table" "prospectmaterials_table" {
name = "drinks"
hash_key = "PK"
billing_mode = "PAY_PER_REQUEST"
read_capacity = 5
write_capacity = 5
attribute {
name = "PK"
type = "S"
}
}
It currently contains 36,000 records.
An example of the data it contains:
PK | Name | Description | Price |
---|---|---|---|
Coke-Coke Cola-Classic beverage-1.00 | Coke Cola | Classic beverage | 1.00 |
Pepsi-Pepsi Cola-Another beverage-1.00 | Pepsi Cola | Another beverage | 1.00 |
Dr. Pepper-Dr. Pepper-Yet another beverage-2.00 | Dr. Pepper | Yet another beverage | 2.00 |
We want to retrieve all ~1000 records with the word "beverage" in the Description
field.
Via an API Gateway endpoint, we want to query the table to retrieve each record which contains "beverage". This query currently breaks with "Invalid operator used in KeyConditionExpression: contains":
{
"TableName": "drinks",
"ConsistentRead": true,
"ExpressionAttributeValues": {
":m": {
"S": "beverage"
}
},
"KeyConditionExpression": "contains(PK,:m)"
}
How should I construct this query so that it performs quickly and returns all the records I require?