DynamoDB Indexing
registration_id | type | manufacturer | model_num |
---|---|---|---|
001 | helicopter | bell | 205 |
002 | airplane | boeing | 747 |
003 | airplane | boeing | 767 |
DynamoDB Local Secondary Index
AWS Command Creating & Adding Local Secondary Index DynanmoDB
1 2 3 4 5 6 |
$ aws dynamodb create-table --table-name Aircraft --attribute-definitions AttributeName=Registration_id,AttributeType=S AttributeName=Type,AttributeType=S AttributeName=Manufacturer,AttributeType=S AttributeName=Model_num,AttributeType=S \ --key-schema AttributeName=Registration_id,KeyType=HASH AttributeName=Type,KeyType=RANGE \ --local-secondary-indexes IndexName=localIndex,KeySchema=["{AttributeName=Registration_id,KeyType=HASH}","{AttributeName=Type,KeyType=RANGE}"],\ Projection="{ProjectionType=INCLUDE ,NonKeyAttributes=["Type"]}" \ --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 |
DynamoDB Global Secondary Index
AWS Command Creating & Adding Global Local Secondary Index DynanmoDB
1 2 3 4 5 6 7 |
$ aws dynamodb create-table --table-name Aircraft --attribute-definitions AttributeName=Registration_id,AttributeType=S AttributeName=Type,AttributeType=S \ AttributeName=Manufacturer,AttributeType=S \ --key-schema AttributeName=Registration_id,KeyType=HASH AttributeName=Type,KeyType=RANGE \ --global-secondary-indexes IndexName=Index,\ KeySchema=["{AttributeName=Registration_id,KeyType=HASH}","{AttributeName=Manufacturer,KeyType=RANGE}"],\ Projection="{ProjectionType=INCLUDE ,NonKeyAttributes=["Manufacturer"]}",\ ProvisionedThroughput="{ReadCapacityUnits=5,WriteCapacityUnits=5}" --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 |
DynamoDB Local Secondary Index (LSI) vs. Global Secondary Index (GSI)
LSI | GSI |
---|---|
Strong Consistency | Eventual Consistency |
Built at table creation | Added after table creation |
Data size under 10GB | Data size over 10GB |
Additional sort key for same partition key | One attribute can be excluded |