iam trying to query a dataset in dynamodb where the primary key is a timestamp. First i wanted to get all data for a specific sensorId. I tried with a scan (scan.json):
{
"sensorId": {
"AttributeValueList": [{
"S": "1234"
}],
"ComparisonOperator": "EQ"
}
}
This Json was used via CLI command:
aws dynamodb scan --table-name sensorData --scan-filter file://scan.json
That was successful and gave me all data for the specified sensorid.
Now if i want to have only the timestamp and sensorId as result, i read about projection-expression and tried to do a query (query.json):
{
":Id":{"S":"1234"}
}
aws cli command
aws dynamodb query --table-name sensorData --key-condition-expression "sensorId= :Id" --expression-attribute-values file://query2.json --projection-expression "timestamp"
Gave me :
An error occurred (ValidationException) when calling the Query operation: Invalid ProjectionExpression: Attribute name is a reserved keyword; reserved keyword: timestamp
But replacing "timestamp" with "sensorId for testing purpose gave me:
An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element: timestamp
And i understand that that sensorId is not valid for key-expression.. KeyConditionExpression accepts only key attributes, hash key and range key. But how to get the result?
I want only the timestamps for a sensorId. Is my Primarykey wrong? should be better to use sensorId as primary key together with timestamp as range key?