Reputation: 331
Actually I am new to dynamodb and the documentation is kinda hard for me to grasp. I already have a working system though I am not aware if it's efficient or if I am following the best practices. So any help will be appreciated.
I am working with a json object which is similar structure like this:
** title need to be unique
{
{
"title": "a title",
"des": "a description,
"published:1495147723000
}, {
"title": "a title 2",
"des": "a description 2,
"published:1495146489000
},
....
}
The whole table will consist only more or less 200 item max. Among those 200 items I need items which only been published in between a specific time period. To accomplish this I am using a set up like this. I just want to know if there other efficient way to do this thing.
My dynamodb table template:
{
TableName: 'Table',
AttributeDefinitions: [{
AttributeName: "title",
AttributeType: "S"
},
{
AttributeName: "published",
AttributeType: "N"
}
],
KeySchema: [{
AttributeName: "title",
KeyType: "HASH"
},
{
AttributeName: "published",
KeyType: "RANGE"
}
],
GlobalSecondaryIndexes: [{
IndexName: "findByTime",
KeySchema: [{
AttributeName: "title",
KeyType: "HASH"
},
{
AttributeName: "published",
KeyType: "RANGE"
}
],
Projection: {
ProjectionType: "ALL"
},
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
}
}],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
}
};
Now, I am fetching items through scanning like this:
docClient.scan(
{
TableName: "Table",
IndexName: "findByDate",
FilterExpression: "feedTime BETWEEN :lastUpdate AND :now",
// rangeKeyConditionExpression: "feedTime >= :ft",
ExpressionAttributeValues: {
":now": Date.now(),
":lastUpdate": Number.parseInt(lastRefreshed)
},
ScanIndexForward: false
},
(e, r) => {
if (e) {
reject(e);
}
resolve(r);
}
);
Upvotes: 0
Views: 47
Reputation: 1462
You don't need global secondary index at all. You can query the table directly. Global secondary index is used only when you want to have hash key and range key different from main table. Currently you are paying twice as much as you need for provisioned capacity.
Using scan to get records seems fine.
Upvotes: 1