How to Create Local Secondary Index in DynamoDB | LSI in DynamoDb
Local Secondary Index: -
FormPost Table
Partition Key= ForumName
Sort Key (Range Key) = LastPostDateTime
{
TableName: "
FormPost",
KeyConditionExpression: " ForumName= :a
and LastPostDateTime=:t",
ExpressionAttributeValues: {
":a": "EC2",
":t": "2015-02-12:11:07:56"
}
}
Only one sort key is applicable for a DynamoDB table so
applying expression condition becomes difficult.
Approach 1 – Scan it Read Capacity costs money – costly and poor
latency
Approach 2 -
FormName==’S3’ narrow down the
data
Subject ==’aaa’ - looks poor
latency and also costly
Approach 3. Create LSI on Subject
{
TableName: “
FormPost”,
KeyConditionExpression: “ ForumName= :a and Subject =:t”,
ExpressionAttributeValues: {
“:a”: “EC2”,
“:t”: “aaa”
}
}
Partition key remain same but the sort key becomes ‘Subject’
Limits:
a.
LSI can be defined at table creation time
b.
5 LSI (Soft Limit) currently but can be checked
with AWS support to increase the limit.
c.
No Extra cost***
Comments
Post a Comment