I'd suggest using a different DB.
DDB doesn't work like an RDBMS or something like Open Search...
GetItem() requires the entire primary key.
- If the table/GSI has just a partition (aka hash) key then you have to have the exact partition key value.
- If you have a partition & sort key defined, you need the exact values for both.
Only with Query() can you do a match on a partial value using the BEGINS_WITH
ComparisonOperator. (Note that CONTAINS
is not supported for Query).
Additionally, that matching is only for the sort key, you still have to pass the exact value of the partition key.
In SQL it would look like so
select *
from table
where partitionKey = :hkvalue
and sortkey like (:skvalue concat '%')
Only a full table Scan() allows you to match using CONTAINS
against some random attribute. It does so by reading the entire table 1MB at a time, which you pay for, and throwing about anything that doesn't match.
In general, if you need to use Scan() often, you're doing something wrong. Either with your design, or with the choice of DDB in the first place.