It is possible to retrieve records from DynamoDB without providing a key condition expression for the primary key (or an index), but you must use the Scan operation, which accesses every item in the table (or index).
An example from AWS's AppSync Scan documentation:
{
"version" : "2017-02-28",
"operation" : "Scan",
"filter" : {
"expression" : "begins_with(title, :title)",
"expressionValues" : {
":title" : { "S" : "${context.arguments.title}" }
},
}
}
DynamoDB Scan API:
The Scan operation returns one or more items and item attributes by accessing every item in a table or a secondary index. To have DynamoDB return fewer items, you can provide a FilterExpression operation.
Regarding your specific question about finding items that do not match a particular primary key:
primaryKey != anInput
If your primaryKey is a composite of partition key + sort key, you should consider using the NOT and logical AND operators with parentheses:
{
"version": "2017-02-28",
"operation": "Scan",
"filter": {
"expression": "NOT (#PK = :PK AND #SK = :SK)",
"expressionNames": {"#PK": "PK", "#SK": "SK"},
"expressionValues": {
":PK":{"S":"some-partition-key"},
":SK":{"S":"some-sort-key"}
},
},
"consistentRead": true,
"limit": 10
}